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

Validate store presence on orders #935

Merged
merged 2 commits into from Mar 8, 2016
Merged

Validate store presence on orders #935

merged 2 commits into from Mar 8, 2016

Conversation

mamhoff
Copy link
Contributor

@mamhoff mamhoff commented Feb 29, 2016

I need to make some behaviour dependent on the store an order is
associated to. Under normal circumstances, the order helper takes care
of that in 100% of cases. However, there's no presence validation on
the store, and for the feature I'm envisioning (Differing default taxation
depending on which store you access) I need every order to have a store.

This PR should be a point of discussion as to wether we want to actually validate
this.

@mamhoff
Copy link
Contributor Author

mamhoff commented Feb 29, 2016

A-ha! If I just make sure the store is somehow set in a before_validation filter, no tests fail. This is now proper PR and not an RfC anymore 👯

@mamhoff mamhoff changed the title RfC Validate store presence on orders Validate store presence on orders Feb 29, 2016
@mamhoff
Copy link
Contributor Author

mamhoff commented Feb 29, 2016

Let me rebase this, the commit comment is still a bit off.

@cbrunsdon
Copy link
Contributor

I'm good by this too, as going forward it would be nice to count on an order having a store. The original migration set up the store_id on orders set them so we should be good to count on this usually being there: 15df7e7

👍

@mamhoff
Copy link
Contributor Author

mamhoff commented Feb 29, 2016

Oh no. So validating :store does essentially nothing, because Spree::Store.default defaults to an empty, invalid store. If I validate :order_id instead, hell ensues.

@mamhoff
Copy link
Contributor Author

mamhoff commented Feb 29, 2016

Take away your thumbs @jhawthorn @cbrunsdon, this needs to be reevaluated.

@jhawthorn
Copy link
Contributor

👍

@mamhoff
Copy link
Contributor Author

mamhoff commented Mar 2, 2016

@tvdeyen Thanks for the raise vs abort comment - I've amended the last commit.

@gmacdougall
Copy link
Member

@mamhoff This looks good to go. Could you please rebase so we can merge this in?

Thanks!

@mamhoff
Copy link
Contributor Author

mamhoff commented Mar 3, 2016

Rebased!

@gmacdougall
Copy link
Member

Github is showing conflicts again. Could you give it another rebase please?

mamhoff added 2 commits March 7, 2016 20:14
I need to make some behaviour dependent on the store an order is
associated to. Under normal circumstances, the order helper takes care
of that in 100% of cases. However, there's no presence validation on
the store, and for the feature I'm envisioning (Differing default taxation
depending on which store you access) I need every order to have a store.

The validation has to be on the `:order_id`, as just validating `:order`
will usually pass because `Spree::Store.default` returns a new, invalid
store if none is there.

This entails a lot of spec setup changes, mostly to make sure a store exists.
Solidus 1.3 will not work well when it encounters an order with no
store set. This commit adds a changelog saying that and as well a
sample rake task that fixes up orders for relatively simple shops.

Also, it introduces a task `solidus:upgrade:one_point_three` which
can be hooked up with other data migration tasks we might need.
@mamhoff
Copy link
Contributor Author

mamhoff commented Mar 7, 2016

Rebased

@adammathys
Copy link
Member

👍 From me. Also, very much appreciate the Rake task.

@tvdeyen
Copy link
Member

tvdeyen commented Mar 8, 2016

Could you please try to use required: true on belongs_to :store, instead if validating the store_id presence?

In Rails 5 this will be default and should work here. Not shure about the before_validation running before that, but we should give it a try.

Either way 👍

@mamhoff
Copy link
Contributor Author

mamhoff commented Mar 8, 2016

Nope, that doesn't work as it generates a validates :store, presence: true, which in turn breaks with the before_validation hook.

I could look into Spree::Store.default, where a || new causes all this trouble, and I haven't quite found out why it is there. There is a possibility that that clause was inserted in order to prevent the kind of trouble I'm trying to solve with the validation. Thoughts, anyone?

gmacdougall added a commit that referenced this pull request Mar 8, 2016
@gmacdougall gmacdougall merged commit c49143c into solidusio:master Mar 8, 2016
@mamhoff mamhoff deleted the validate-store-presence branch May 24, 2016 19:46
@jhawthorn jhawthorn mentioned this pull request Jun 7, 2016
3 tasks
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.

6 participants