Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spec restock after order cancellation #12938

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions spec/models/spree/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -375,27 +375,52 @@
end
end

describe "#cancel" do
describe "#cancel!" do
let(:order) { create(:order_with_totals_and_distribution, :completed) }

before { order.cancel! }

it "should cancel the order" do
expect(order.state).to eq 'canceled'
expect { order.cancel! }.to change { order.state }.to("canceled")
end

it "should cancel the shipments" do
expect(order.shipments.pluck(:state)).to eq ['canceled']
expect { order.cancel! }.to change {
order.shipments.pluck(:state)
}.to(["canceled"])
end

context "when payment has not been taken" do
context "and payment is in checkout state" do
it "should change the state of the payment to void" do
order.payments.reload
expect(order.payments.pluck(:state)).to eq ['void']
expect {
order.cancel!
order.payments.reload
}.to change {
order.payments.pluck(:state)
}.to(["void"])
end
end
end

it "restocks items without reload" do
pending "Cancelling a newly created order updates shipments without callbacks"
# But in production, orders are always created in one request and
# cancelled in another request. This is only an issue in specs.

expect { order.cancel }.to change {
order.variants.first.on_hand
}.by(1)
end

it "restocks items" do
# If we don't reload the order, it keeps thinking that its shipping
# address changed and triggers a shipment update without shipment
# callbacks. This can be removed if the above spec passes.
order.reload

expect { order.cancel }.to change {
order.variants.first.on_hand
}.by(1)
end
end

describe "#resume" do
Expand Down
Loading