From 03fc63ad14969869df6c0011d717143723ad442b Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Tue, 11 May 2021 02:52:04 +0100 Subject: [PATCH] Remove #order_update! from line item after_save callback --- app/models/spree/line_item.rb | 1 - app/models/spree/order_contents.rb | 1 + .../admin/bulk_line_items_controller_spec.rb | 2 +- spec/models/spree/line_item_spec.rb | 1 - spec/services/order_syncer_spec.rb | 10 ++++++++-- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/models/spree/line_item.rb b/app/models/spree/line_item.rb index 25636291ed..38e92f0ccd 100644 --- a/app/models/spree/line_item.rb +++ b/app/models/spree/line_item.rb @@ -230,7 +230,6 @@ module Spree # update the order totals, etc. order.create_tax_charge! - order.update_order! end def update_inventory_before_destroy diff --git a/app/models/spree/order_contents.rb b/app/models/spree/order_contents.rb index 4ee92ca906..dc28749e14 100644 --- a/app/models/spree/order_contents.rb +++ b/app/models/spree/order_contents.rb @@ -76,6 +76,7 @@ module Spree end def update_order + order.update_order! order.reload end end diff --git a/spec/controllers/admin/bulk_line_items_controller_spec.rb b/spec/controllers/admin/bulk_line_items_controller_spec.rb index 966722bdc7..2351175485 100644 --- a/spec/controllers/admin/bulk_line_items_controller_spec.rb +++ b/spec/controllers/admin/bulk_line_items_controller_spec.rb @@ -212,7 +212,7 @@ describe Admin::BulkLineItemsController, type: :controller do expect(line_item1.order).to receive(:reload).with(lock: true) expect(line_item1.order).to receive(:update_line_item_fees!) expect(line_item1.order).to receive(:update_order_fees!) - expect(line_item1.order).to receive(:update_order!).twice + expect(line_item1.order).to receive(:update_order!) spree_put :update, params end diff --git a/spec/models/spree/line_item_spec.rb b/spec/models/spree/line_item_spec.rb index a98685bab4..c740d4b018 100644 --- a/spec/models/spree/line_item_spec.rb +++ b/spec/models/spree/line_item_spec.rb @@ -11,7 +11,6 @@ module Spree it 'should update inventory, totals, and tax' do # Regression check for Spree #1481 expect(line_item.order).to receive(:create_tax_charge!) - expect(line_item.order).to receive(:update_order!) line_item.quantity = 2 line_item.save end diff --git a/spec/services/order_syncer_spec.rb b/spec/services/order_syncer_spec.rb index 93c91448e4..f2158aaff0 100644 --- a/spec/services/order_syncer_spec.rb +++ b/spec/services/order_syncer_spec.rb @@ -443,7 +443,10 @@ describe OrderSyncer do before { variant.update_attribute(:on_hand, 3) } context "when the changed line_item quantity matches the new quantity on the subscription line item" do - before { changed_line_item.update(quantity: 3) } + before do + changed_line_item.update(quantity: 3) + order.update_order! + end it "does not change the quantity, and doesn't add the order to order_update_issues" do expect(order.reload.total.to_f).to eq 99.95 @@ -456,7 +459,10 @@ describe OrderSyncer do end context "when the changed line_item quantity doesn't match the new quantity on the subscription line item" do - before { changed_line_item.update(quantity: 2) } + before do + changed_line_item.update(quantity: 2) + order.update_order! + end it "does not change the quantity, and adds the order to order_update_issues" do expect(order.reload.total.to_f).to eq 79.96