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

[Spree Upgrade] Fix order_updater_spec by using create (instead of build) in shipment #2785

Merged

Conversation

luisramos0
Copy link
Contributor

Also simplified spec by using prebuild shipment_with and shipping_method factories

What? Why?

Closes #2784

What should we test?

Order Updater spec should be green

@luisramos0 luisramos0 self-assigned this Sep 29, 2018
@luisramos0
Copy link
Contributor Author

I have checked the build and spec/models/order_updater_spec.rb has no errors now.

@luisramos0 luisramos0 force-pushed the 2-0-order-updater-fix branch from 3a39b50 to f03a2e0 Compare September 30, 2018 00:16
selected: true
)
end
let(:shipment) { create(:shipment_with, :shipping_method, shipping_method: shipping_method) }
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't the use of the :shipping_method trait a bit redundant here? As we're passing a shipping method in this would be equivalent of the simpler create(:shipment, shipping_method: shipping_method). Am I missing something?

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 dont think so.
The spree shipment factory does create(:shipping_method)
but the new ofn shipment_with factory has the same create(:shipping_method) but inside a transient block, which means that if shipping_method is provided, it will get used.
and in this case we are providing different shipping_methods, once as pickup and then as delivery.
Makes sense?

Copy link
Contributor

Choose a reason for hiding this comment

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

So, for me to understand, if no shipping method is provided none will be created, am I right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, if no shipping_method is provided the code inside transient is used, in this specific shipment_with factory, the default :shipping_method factory will be used.

selected: true
)
end
context 'when shipping method is pickup' do
Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for sticking to the more meaningful pickup/delivery naming 👏

)
end
context 'when shipping method is pickup' do
let(:shipping_method) { create(:shipping_method_with, :pickup) }
Copy link
Contributor

Choose a reason for hiding this comment

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

is there any reason to have a separate shipping method factory other than better readability when using traits?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, I could have extended the spree shipping_method factory, but I think it's better if we keep it with a different name. so, not just readability but also separation from spree code (I think it's similar to extending the class instead of using class_eval).

@mkllnk
Copy link
Member

mkllnk commented Oct 14, 2018

@sauloperez Can you give this another review?

@luisramos0
Copy link
Contributor Author

lets wait for the merge from master before we merge this one.

…. Also simplified spec by using prebuild shipment_with and shipping_method factories
@luisramos0 luisramos0 force-pushed the 2-0-order-updater-fix branch from f03a2e0 to 5700164 Compare October 16, 2018 15:37
@luisramos0
Copy link
Contributor Author

luisramos0 commented Oct 16, 2018

Although there were no conflicts, this spec was a difficult merge on #2863
So I decided to rebase this one and run the tests. It's all good. No code change since the approvals, so I am using my merger powers on this one.

@luisramos0 luisramos0 merged commit faf8322 into openfoodfoundation:2-0-stable Oct 16, 2018
@luisramos0 luisramos0 deleted the 2-0-order-updater-fix branch October 16, 2018 15:43
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.

3 participants