-
Notifications
You must be signed in to change notification settings - Fork 0
preserve shipping method when shipments change #3
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| require 'spec_helper' | ||
|
|
||
| describe Spree::Order do | ||
| let(:order) { create(:order_with_line_items) } | ||
| let(:quadcopter) { create(:shipping_method, name: "Quads'r'us", code: "QUADSRUS", cost: 200) } | ||
|
|
||
| it "preserves selected shipping method when update_cart and next! called" do | ||
|
Author
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. I'd appreciate a 2nd set of eyes (and corresponding brain) to help ensure the test cases here are accurate. |
||
| #choose more expensive quadcopter shipping method | ||
| original_shipment = order.shipments.first | ||
| quadcopter_rate = original_shipment.add_shipping_method(quadcopter) | ||
| original_shipment.selected_shipping_rate_id = quadcopter_rate.id | ||
|
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. do we need to persist here?
Author
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. You'd think so, but no. 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. eek ok |
||
| expect(order.shipments.first.shipping_method).to eq quadcopter | ||
|
|
||
| order.contents.update_cart({}) #contents don't really matter | ||
| order.contents.advance | ||
|
|
||
| expect(order.shipments.first.shipping_method).to eq quadcopter | ||
| end | ||
|
|
||
| let(:cheap_ups_cost) { 10 } | ||
|
|
||
| it "reaching delivery step with no explicit selection selects cheapest shipping rate" do | ||
| # ... even if the shipping method is created after the order | ||
| order.contents.add(create(:variant), 1) | ||
| cheap_ups = create(:shipping_method, name: "Cheap UPS Ground", cost: cheap_ups_cost) | ||
|
|
||
| order.contents.advance | ||
| final_selected_shipping_rate = order.shipments.first.selected_shipping_rate | ||
|
|
||
| expect(final_selected_shipping_rate.shipping_method).to eq cheap_ups | ||
| expect(final_selected_shipping_rate.cost).to eq cheap_ups_cost | ||
| end | ||
| 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.
I'm a bit nervous about these changes to the factories, but they were the simplest way to get tests passing
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'm less concerned about these after chatting through them. and there's a potential performance benefit!
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. Your insight helped my confidence in this change too.