Skip to content

Commit d22210b

Browse files
committed
WIP: Preventing InMemoryOrderUpdater#update_shipment_amounts from making 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
1 parent 84c1ce4 commit d22210b

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

core/app/models/spree/in_memory_order_updater.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def initialize(order)
1919
def recalculate(persist: true)
2020
order.transaction do
2121
update_item_count
22-
update_shipment_amounts
22+
update_shipment_amounts(persist:)
2323
update_totals
2424
if order.completed?
2525
update_payment_state
@@ -132,8 +132,8 @@ def update_totals
132132
update_adjustment_total
133133
end
134134

135-
def update_shipment_amounts
136-
shipments.each(&:update_amounts)
135+
def update_shipment_amounts(persist:)
136+
shipments.each { _1.update_amounts(persist:) }
137137
end
138138

139139
# give each of the shipments a chance to update themselves

core/spec/models/spree/in_memory_order_updater_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,30 @@ module Spree
3737
expect(order.item_count).to eq 1
3838
expect(order.reload.item_count).to eq 0
3939
end
40+
41+
context 'when a shipment is attached to the order' do
42+
let(:shipment) { create(:shipment) }
43+
44+
before do
45+
order.shipments << shipment
46+
end
47+
48+
it 'does not make manipulative database queries' do
49+
expect {
50+
subject
51+
}.not_to make_database_queries(manipulative: true)
52+
end
53+
54+
context 'when the shipment has a selected shipping rate' do
55+
let(:shipment) { create(:shipment, shipping_rates: [build(:shipping_rate, selected: true)]) }
56+
57+
it 'does not make manipulative database queries' do
58+
expect {
59+
subject
60+
}.not_to make_database_queries(manipulative: true)
61+
end
62+
end
63+
end
4064
end
4165

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

0 commit comments

Comments
 (0)