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

Add a spec for #transfer_to_location to verify the attributes of the new shipment #1141

Merged

Conversation

hectoregm
Copy link
Contributor

When a shipment split is done the new shipment created by #transfer_to_location doesn't associate
the order shipping address to this new shipment so all new shipments have nil for address.

it 'transfers unit to a new shipment with given location' do
order = create(:completed_order_with_totals, line_items_count: 2)
shipment = order.shipments.first
variant = order.inventory_units.collect(&:variant).first

Choose a reason for hiding this comment

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

Prefer map over collect.

@hectoregm hectoregm force-pushed the add_address_to_new_shipment_after_split branch from e4f54c6 to 17887fd Compare May 11, 2016 22:52
@hectoregm
Copy link
Contributor Author

The main problem is that splitting a completed order doesn't fill the address and the shipping method
for the new shipment, this later raises an error when doing a transition to shipped:

ActiveRecord::RecordInvalid: Validation of Address can't be blank, Shipping method can't be blank.

https://github.com/solidusio/solidus/blob/master/core/app/models/spree/order_shipping.rb#L51

when creating a Spree::Carton called on the after_transition hook for shipped.

@mamhoff
Copy link
Contributor

mamhoff commented May 13, 2016

Thanks, this makes sense to me. @forkata Any idea why this was omitted in the first place?

Btw really nice specs.

@forkata
Copy link
Contributor

forkata commented May 14, 2016

@mamhoff It appears that the address association on shipment isn't used consistently and this was probably omitted by mistake. I looked through the history of this code and as far back as I could trace it, it seems this would have been an issue b252e9a.

Related to this there is a proposed change to completely remove the address association on shipment here #1138 and always use the Order#ship_address instead. If we decide to go down that direction, then this change may no longer be needed.

@hectoregm
Copy link
Contributor Author

@forkata yeah I read the proposal to delegate to Order#ship_address but I think we can use this spec
for #trasnfer_for_location right ?, I could remove address expectation and the injection of address.

@forkata
Copy link
Contributor

forkata commented May 14, 2016

@hectoregm We can definitely use the spec, thank you for adding that. I would keep an eye on what the decision is regarding the address association on Shipment and make any changes based on that if needed.

shipment = order.shipments.first
variant = order.inventory_units.collect(&:variant).first

expect do
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice if we can wrap all these expectations in an aggregate_failures block so we can see multiple failures in a single run.

http://www.rubydoc.info/github/rspec/rspec-expectations/RSpec%2FMatchers%3Aaggregate_failures

@hectoregm hectoregm force-pushed the add_address_to_new_shipment_after_split branch 2 times, most recently from a78f7ac to 3b5ee23 Compare May 16, 2016 21:05
@hectoregm hectoregm force-pushed the add_address_to_new_shipment_after_split branch from 3b5ee23 to 39fd963 Compare May 16, 2016 21:18
@hectoregm hectoregm changed the title Add an order ship_address as the address of a new shipment split Add a spec for #transfer_to_location to verify the attributes of the new shipment May 16, 2016
@hectoregm
Copy link
Contributor Author

@forkata made the changes we mentioned and added aggregate_failures block

@jhawthorn
Copy link
Contributor

👍

@jhawthorn jhawthorn merged commit d3a9a67 into solidusio:master Jun 29, 2016
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.

5 participants