Skip to content

Commit 12d6b81

Browse files
forkataadammathyssenemsoystewartKendra Riga
authored andcommitted
Rename method that recalculates shipment state
Update implies that we are persisting the change in Rails, which this method does not do. Co-authored-by: Adam Mueller <[email protected]> Co-authored-by: Senem Soy <[email protected]> Co-authored-by: Andrew Stewart <[email protected]> Co-authored-by: Kendra Riga <[email protected]> Co-authored-by: Sofia Besenski <[email protected]> Co-authored-by: benjamin wil <[email protected]>
1 parent 3660447 commit 12d6b81

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

core/app/models/spree/order.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def valid_credit_cards
418418

419419
def fulfill!
420420
shipments.each { |shipment| shipment.update_state if shipment.persisted? }
421-
recalculator.update_shipment_state
421+
recalculator.recalculate_shipment_state
422422
save!
423423
end
424424

@@ -764,7 +764,7 @@ def finalize
764764
shipment.finalize!
765765
end
766766

767-
recalculator.update_shipment_state
767+
recalculator.recalculate_shipment_state
768768
save!
769769

770770
touch :completed_at

core/app/models/spree/order_updater.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def recalculate
2424
if order.completed?
2525
update_payment_state
2626
update_shipments
27-
update_shipment_state
27+
recalculate_shipment_state
2828
end
2929
Spree::Bus.publish(:order_recalculated, order:)
3030
persist_totals
@@ -43,13 +43,15 @@ def recalculate
4343
# pending when all Shipments are in the "pending" state
4444
#
4545
# The +shipment_state+ value helps with reporting, etc. since it provides a quick and easy way to locate Orders needing attention.
46-
def update_shipment_state
46+
def recalculate_shipment_state
4747
log_state_change('shipment') do
4848
order.shipment_state = determine_shipment_state
4949
end
5050

5151
order.shipment_state
5252
end
53+
alias_method :update_shipment_state, :recalculate_shipment_state
54+
deprecate update_shipment_state: :recalculate_shipment_state, deprecator: Spree.deprecator
5355

5456
# Updates the +payment_state+ attribute according to the following logic:
5557
#

core/spec/models/spree/order_updater_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ module Spree
268268
it "logs a state change for the shipment" do
269269
create :shipment, order:, state: "pending"
270270

271-
expect { updater.update_shipment_state }
271+
expect { updater.recalculate_shipment_state }
272272
.to enqueue_job(Spree::StateChangeTrackingJob)
273273
.with(order, nil, "pending", a_kind_of(Time), "shipment")
274274
.once
@@ -280,28 +280,28 @@ module Spree
280280

281281
it "is backordered" do
282282
allow(order).to receive_messages backordered?: true
283-
updater.update_shipment_state
283+
updater.recalculate_shipment_state
284284

285285
expect(order.shipment_state).to eq('backorder')
286286
end
287287

288288
it "is nil" do
289-
updater.update_shipment_state
289+
updater.recalculate_shipment_state
290290
expect(order.shipment_state).to be_nil
291291
end
292292

293293
["shipped", "ready", "pending"].each do |state|
294294
it "is #{state}" do
295295
create(:shipment, order:, state:)
296-
updater.update_shipment_state
296+
updater.recalculate_shipment_state
297297
expect(order.shipment_state).to eq(state)
298298
end
299299
end
300300

301301
it "is partial" do
302302
create(:shipment, order:, state: 'pending')
303303
create(:shipment, order:, state: 'ready')
304-
updater.update_shipment_state
304+
updater.recalculate_shipment_state
305305
expect(order.shipment_state).to eq('partial')
306306
end
307307
end
@@ -427,7 +427,7 @@ module Spree
427427
end
428428

429429
it "updates shipment state" do
430-
expect(updater).to receive(:update_shipment_state)
430+
expect(updater).to receive(:recalculate_shipment_state)
431431
updater.recalculate
432432
end
433433

@@ -456,7 +456,7 @@ module Spree
456456
end
457457

458458
it "doesnt update shipment state" do
459-
expect(updater).not_to receive(:update_shipment_state)
459+
expect(updater).not_to receive(:recalculate_shipment_state)
460460
updater.recalculate
461461
end
462462

core/spec/models/spree/payment_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@
745745

746746
it "updates payment_state and shipments" do
747747
expect(order.recalculator).to receive(:update_payment_state)
748-
expect(order.recalculator).to receive(:update_shipment_state)
748+
expect(order.recalculator).to receive(:recalculate_shipment_state)
749749
Spree::Payment.create!(amount: 100, order:, payment_method:)
750750
end
751751
end

0 commit comments

Comments
 (0)