Skip to content

Commit

Permalink
Rename method that recalculates shipment state
Browse files Browse the repository at this point in the history
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 Willems <[email protected]>
  • Loading branch information
7 people committed Nov 8, 2024
1 parent 203ed70 commit 8040224
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
8 changes: 5 additions & 3 deletions core/app/models/spree/in_memory_order_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def recalculate(persist: true)
if order.completed?
update_payment_state
update_shipments
update_shipment_state
recalculate_shipment_state
end
Spree::Bus.publish :order_recalculated, order: order

Expand All @@ -34,7 +34,7 @@ def recalculate(persist: true)
alias_method :update, :recalculate
deprecate update: :recalculate, deprecator: Spree.deprecator

# Updates the +shipment_state+ attribute according to the following logic:
# Recalculates the +shipment_state+ attribute according to the following logic:
#
# shipped when all Shipments are in the "shipped" state
# partial when at least one Shipment has a state of "shipped" and there is another Shipment with a state other than "shipped"
Expand All @@ -44,13 +44,15 @@ def recalculate(persist: true)
# pending when all Shipments are in the "pending" state
#
# The +shipment_state+ value helps with reporting, etc. since it provides a quick and easy way to locate Orders needing attention.
def update_shipment_state
def recalculate_shipment_state
log_state_change('shipment') do
order.shipment_state = determine_shipment_state
end

order.shipment_state
end
alias_method :update_shipment_state, :recalculate_shipment_state
deprecate update_shipment_state: :recalculate_shipment_state, deprecator: Spree.deprecator

# Updates the +payment_state+ attribute according to the following logic:
#
Expand Down
12 changes: 6 additions & 6 deletions core/spec/models/spree/in_memory_order_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,28 +227,28 @@ module Spree

it "is backordered" do
allow(order).to receive_messages backordered?: true
updater.update_shipment_state
updater.recalculate_shipment_state

expect(order.shipment_state).to eq('backorder')
end

it "is nil" do
updater.update_shipment_state
updater.recalculate_shipment_state
expect(order.shipment_state).to be_nil
end

["shipped", "ready", "pending"].each do |state|
it "is #{state}" do
create(:shipment, order: order, state: state)
updater.update_shipment_state
updater.recalculate_shipment_state
expect(order.shipment_state).to eq(state)
end
end

it "is partial" do
create(:shipment, order: order, state: 'pending')
create(:shipment, order: order, state: 'ready')
updater.update_shipment_state
updater.recalculate_shipment_state
expect(order.shipment_state).to eq('partial')
end
end
Expand Down Expand Up @@ -361,7 +361,7 @@ module Spree
end

it "updates shipment state" do
expect(updater).to receive(:update_shipment_state)
expect(updater).to receive(:recalculate_shipment_state)
updater.recalculate
end

Expand Down Expand Up @@ -390,7 +390,7 @@ module Spree
end

it "doesnt update shipment state" do
expect(updater).not_to receive(:update_shipment_state)
expect(updater).not_to receive(:recalculate_shipment_state)
updater.recalculate
end

Expand Down

0 comments on commit 8040224

Please sign in to comment.