Skip to content

Commit

Permalink
WIP: Preventing InMemoryOrderUpdater#update_shipment_amounts from mak…
Browse files Browse the repository at this point in the history
…ing database writes

We have prevented a write call to update the cost and updated_at of a shipment, but currently the spec in_memory_order_updater_spec.rb:57 is failing due to a write call to update shipments promo totals

This is probably the next thing we want to look into when picking up this work
  • Loading branch information
Noah-Silvera committed Oct 25, 2024
1 parent 84c1ce4 commit d22210b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
6 changes: 3 additions & 3 deletions core/app/models/spree/in_memory_order_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def initialize(order)
def recalculate(persist: true)
order.transaction do
update_item_count
update_shipment_amounts
update_shipment_amounts(persist:)
update_totals
if order.completed?
update_payment_state
Expand Down Expand Up @@ -132,8 +132,8 @@ def update_totals
update_adjustment_total
end

def update_shipment_amounts
shipments.each(&:update_amounts)
def update_shipment_amounts(persist:)
shipments.each { _1.update_amounts(persist:) }
end

# give each of the shipments a chance to update themselves
Expand Down
24 changes: 24 additions & 0 deletions core/spec/models/spree/in_memory_order_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,30 @@ module Spree
expect(order.item_count).to eq 1
expect(order.reload.item_count).to eq 0
end

context 'when a shipment is attached to the order' do
let(:shipment) { create(:shipment) }

before do
order.shipments << shipment
end

it 'does not make manipulative database queries' do
expect {
subject
}.not_to make_database_queries(manipulative: true)
end

context 'when the shipment has a selected shipping rate' do
let(:shipment) { create(:shipment, shipping_rates: [build(:shipping_rate, selected: true)]) }

it 'does not make manipulative database queries' do
expect {
subject
}.not_to make_database_queries(manipulative: true)
end
end
end
end

context "when the persist flag is set to 'true'" do
Expand Down

0 comments on commit d22210b

Please sign in to comment.