-
-
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
Conversation
This is more realistic and robust. Don't mock the class under test (even though `touch` is actually provided by Active Record).
The spec was asserting on all shipments of the order but there were one. In consequence, the spec didn't assert anything. Now I set up a shipment that is asserted on. I'm stil not sure how useful this spec is though.
The next test case wasn't asserting anything as well. The referenced method `decrease_stock_for_variant` doesn't actually exist.
It's more realistic this way.
order.shipments.each do |shipment| | ||
expect(shipment).to receive(:update!) | ||
expect(shipment).to receive(:finalize!) | ||
end |
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.
Sorry for the typo in the commit message. order.shipments
was empty.
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 find ! It's interesting to find out another way that spec can fail to test anything. Are shipments actually used in OFN ?
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.
Great improvements 💯
order.reload | ||
}.to change { | ||
order.completed_at | ||
}.from(nil) |
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..
What? Why?
I was looking at existing specs around stock allocation when an order is completed. And I stumbled across some ineffective specs of the Order model which I fixed here.
What should we test?
Release notes
Changelog Category (reviewers may add a label for the release notes):
The title of the pull request will be included in the release notes.
Dependencies
Documentation updates