-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fix spec failure due to DB order #2607
Fix spec failure due to DB order #2607
Conversation
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.
I think the spec is now harder to read.
@@ -39,7 +39,7 @@ | |||
end | |||
end.to change { Spree::Shipment.count }.by(1) | |||
|
|||
new_shipment = order.shipments.last | |||
new_shipment = (order.shipments.to_a - [shipment])[0] |
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.
Why not order.shipments.order(:created_at).last
or order.shipments.sort_by(&:created_at).last
if we don't want to reload the shipments again? Would be more readable.
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.
I did this out of habit due to MySQL second timestamp issues, but this isn't necessary as of #2598 🎉. I will use your suggestion.
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.
Ah. Thanks for clarifying. I always forget the darn mysql default precision.
The shipments association here was being loaded in the recalculate. The association itself isn't ordered, so the shipments could be in any order. Because of this, shipments.last wasn't necessarily the most recent shipment, and this spec could fail.
5900895
to
6586178
Compare
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.
Thank you
Merging ahead of our usual time period, as this fixes spec issues. |
The shipments association here was being loaded in the recalculate. The association itself isn't ordered, so the shipments could be in any order. Because of this, shipments.last wasn't necessarily the most recent shipment, and this spec could fail.
This probably started failing after #2555 was merged