File tree Expand file tree Collapse file tree 2 files changed +29
-3
lines changed
Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -221,10 +221,10 @@ def determine_state(order)
221221 # ready all other cases
222222 def recalculate_state
223223 self . state =
224- if order . canceled? || inventory_units . all? ( &:canceled? )
225- "canceled"
226- elsif shipped?
224+ if shipped?
227225 "shipped"
226+ elsif order . canceled? || inventory_units . all? ( &:canceled? )
227+ "canceled"
228228 elsif !order . can_ship?
229229 "pending"
230230 elsif can_transition_from_pending_to_ready?
Original file line number Diff line number Diff line change 109109 it "adjusts the order" do
110110 expect { subject } . to change { order . reload . total } . by ( -40.0 )
111111 end
112+
113+ context "when cancelling all items in a completed order" do
114+ let! ( :order ) { create ( :completed_order_with_totals , line_items_attributes : [ { quantity : } ] ) }
115+
116+ subject { described_class . new ( order ) . short_ship ( order . inventory_units ) }
117+
118+ it "updates all of the inventory units" do
119+ expect { subject } . to change { order . inventory_units . canceled . count } . to ( quantity )
120+ end
121+
122+ it "updates the shipment state" do
123+ expect { subject } . to change { order . shipments . first . reload . state } . to ( "canceled" )
124+ end
125+
126+ context "when the shipment is already shipped" do
127+ let! ( :order ) { create ( :shipped_order , line_items_attributes : [ { quantity : } ] ) }
128+
129+ it "updates all of the inventory units" do
130+ expect { subject } . to change { order . inventory_units . canceled . count } . to ( quantity )
131+ end
132+
133+ it "does not update the shipment state" do
134+ expect { subject } . not_to change { order . shipments . first . reload . state } . from ( "shipped" )
135+ end
136+ end
137+ end
112138 end
113139
114140 it "sends a cancellation email" do
You can’t perform that action at this time.
0 commit comments