-
-
Notifications
You must be signed in to change notification settings - Fork 730
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
Improve spec for Spree::Order#finalize! #12662
Merged
+21
−20
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
eea227b
Style order spec block a tiny bit
mkllnk 94d560d
Replace expecting method call with outcome
mkllnk cb4e7d6
Fix spec to assert updating shipments
mkllnk 2e36c69
Test resulting stock instead of method calls
mkllnk a37b0eb
Replace mocking on tested order object
mkllnk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -216,35 +216,36 @@ | |
end | ||
end | ||
|
||
context "#finalize!" do | ||
let(:order) { Spree::Order.create } | ||
describe "#finalize!" do | ||
subject(:order) { Spree::Order.create } | ||
|
||
it "should set completed_at" do | ||
expect(order).to receive(:touch).with(:completed_at) | ||
order.finalize! | ||
expect { | ||
order.finalize! | ||
order.reload | ||
}.to change { | ||
order.completed_at | ||
}.from(nil) | ||
end | ||
|
||
it "should sell inventory units" do | ||
order.shipments.each do |shipment| | ||
expect(shipment).to receive(:update!) | ||
expect(shipment).to receive(:finalize!) | ||
end | ||
Comment on lines
-227
to
-230
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the typo in the commit message. |
||
order.finalize! | ||
end | ||
it "updates shipments and decreases stock" do | ||
order = create(:order_ready_for_confirmation) | ||
shipment = order.shipments.first | ||
shipment.update_columns(updated_at: 1.minute.ago) | ||
|
||
it "should decrease the stock for each variant in the shipment" do | ||
order.shipments.each do |shipment| | ||
expect(shipment.stock_location).to receive(:decrease_stock_for_variant) | ||
end | ||
order.finalize! | ||
expect { | ||
order.finalize! | ||
}.to change { order.variants.first.on_hand }.by(-1) | ||
.and change { shipment.updated_at } | ||
end | ||
|
||
it "should change the shipment state to ready if order is paid" do | ||
Spree::Shipment.create(order:) | ||
order.shipments.reload | ||
order = create(:order_ready_for_confirmation) | ||
|
||
allow(order).to receive_messages(paid?: true, complete?: true) | ||
order.finalize! | ||
order.payments.first.capture! | ||
order.next! # calls `finalize!` | ||
order.reload # reload so we're sure the changes are persisted | ||
|
||
expect(order.shipment_state).to eq 'ready' | ||
end | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice way to test this. I probably would have gone down the unnecessary task of freezing time and checking it changed
to
the current time..