Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
fix doubled order canceled event (#13899)
Kacper Mękarskie9d46c296c72
diff --git a/spree/core/app/models/spree/order.rb b/spree/core/app/models/spree/order.rbindex 7727eb40c5..7b3c117bb3 100644--- a/spree/core/app/models/spree/order.rb+++ b/spree/core/app/models/spree/order.rb@@ -1012,7 +1012,6 @@ module Spreeupdate_with_updater!send_order_canceled_webhook- publish_order_canceled_eventenddef after_resume@@ -1093,10 +1092,6 @@ module Spreepublish_event('order.completed')end- def publish_order_canceled_event- publish_event('order.canceled')- end-def publish_order_resumed_eventpublish_event('order.resumed')enddiff --git a/spree/core/spec/models/spree/order_spec.rb b/spree/core/spec/models/spree/order_spec.rbindex e3b329b60a..b0199eae62 100644--- a/spree/core/spec/models/spree/order_spec.rb+++ b/spree/core/spec/models/spree/order_spec.rb@@ -292,16 +292,6 @@ describe Spree::Order, type: :model doexpect(order.payments.store_credits).to all(have_attributes(state: 'void'))endend-- context 'events', :events do- let(:order) { create(:completed_order_with_totals, store: store) }-- it 'publishes order.canceled event' do- expect(order).to receive(:publish_event).with('order.canceled').at_least(:once)- allow(order).to receive(:publish_event).with(anything)- order.cancel!- end- endenddescribe '#after_resume' dodiff --git a/spree/core/spec/services/spree/orders/cancel_spec.rb b/spree/core/spec/services/spree/orders/cancel_spec.rbindex 9da47d86bd..3e8dd82f2f 100644--- a/spree/core/spec/services/spree/orders/cancel_spec.rb+++ b/spree/core/spec/services/spree/orders/cancel_spec.rb@@ -14,6 +14,11 @@ module Spreeit { expect(result).to be_success }it { expect { result }.to change(order, :state).to('canceled') }it { expect(result.value).to eq(order) }++ it 'publishes order.canceled event' do+ expect(order).to receive(:publish_event).with('order.canceled')+ result+ endendcontext 'incomplete order' do@@ -21,6 +26,11 @@ module Spreeit { expect(result).to be_failure }it { expect(result.error).to be_present }++ it 'does not publish order.canceled event' do+ expect(order).not_to receive(:publish_event).with('order.canceled')+ result+ endendenddiff --git a/spree/emails/spec/models/spree/order_spec.rb b/spree/emails/spec/models/spree/order_spec.rbindex 82b2a0d6ee..03577d3c6f 100644--- a/spree/emails/spec/models/spree/order_spec.rb+++ b/spree/emails/spec/models/spree/order_spec.rb@@ -19,42 +19,4 @@ describe Spree::Order, type: :model doorder.finalize!endend-- describe '#cancel' do- let(:order) { build(:order) }- let!(:variant) { create(:variant) }- let!(:inventory_units) { create_list(:inventory_unit, 2, variant: variant) }- let!(:shipment) { create(:shipment) }- let!(:line_items) { create_list(:line_item, 2, order: order, price: 10) }-- before do- allow(shipment).to receive_messages inventory_units: inventory_units, order: order- allow(order).to receive_messages shipments: [shipment]-- allow(order.line_items).to receive(:find_by).with(hash_including(:variant_id)) { line_items.first }-- allow(order).to receive_messages completed?: true- allow(order).to receive_messages allow_cancel?: true-- shipments = [shipment]- allow(order).to receive_messages shipments: shipments- allow(shipments).to receive_messages states: []- allow(shipments).to receive_messages ready: []- allow(shipments).to receive_messages pending: []- allow(shipments).to receive_messages shipped: []- allow(shipments).to receive_message_chain(:sum, :cost).and_return(shipment.cost)-- allow_any_instance_of(Spree::OrderUpdater).to receive(:update_adjustment_total).and_return(10)- end-- it 'publishes order.canceled event when canceling', events: true do- allow(shipment).to receive(:cancel!)- allow(order).to receive :restock_items!-- expect(order).to receive(:publish_event).with('order.canceled')- allow(order).to receive(:publish_event).with(anything)-- order.cancel!- end- endend