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

Fix spec failure due to DB order #2607

Merged
merged 1 commit into from
Mar 8, 2018

Conversation

jhawthorn
Copy link
Contributor

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

Copy link
Member

@tvdeyen tvdeyen left a 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]
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.
@jhawthorn jhawthorn force-pushed the fix_db_order_error_shipments branch from 5900895 to 6586178 Compare March 8, 2018 00:22
Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

@tvdeyen
Copy link
Member

tvdeyen commented Mar 8, 2018

Merging ahead of our usual time period, as this fixes spec issues.

@tvdeyen tvdeyen merged commit 5c5eed1 into solidusio:master Mar 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants