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 ability to run validations in order updater #3645

Merged
merged 9 commits into from
Jun 4, 2020

Conversation

kennyadsl
Copy link
Member

Description

This PR is a continuation of the old #2208.

It's only adding to the original work a preference that allows people to knowingly switch to the new behavior with:

Spree::Config.run_order_validations_on_order_updater = true

It also adds a deprecation warning booting the application if the value used for the preference is false.

Checklist:

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • [ ] I have updated Guides and README accordingly to this change (if needed)
  • I have added tests to cover this change (if needed)
  • [ ] I have attached screenshots to this PR for visual changes (if needed)

@kennyadsl kennyadsl added Needs Work release:major Breaking change on hold until next major release labels May 29, 2020
@kennyadsl kennyadsl added this to the 2.11 milestone May 29, 2020
@kennyadsl kennyadsl self-assigned this May 29, 2020
@kennyadsl kennyadsl added Needs Core Team Review changelog:solidus_core Changes to the solidus_core gem and removed release:major Breaking change on hold until next major release Needs Work labels May 29, 2020
Copy link
Member

@spaghetticode spaghetticode left a comment

Choose a reason for hiding this comment

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

@mamhoff @kennyadsl thanks! 👍

@@ -64,6 +64,15 @@ class Engine < ::Rails::Engine
caller
)
end

if Spree::Config.run_order_validations_on_order_updater == false
Copy link
Member

Choose a reason for hiding this comment

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

Any reason for not allowing also other falsy values (ie. nil) here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think it can be nil or any other thing since it's initialized with true as default. Of course, unless you initialize this with a non-boolean value. Anyway, the only accepted value that should not raise a deprecation error is true so I'm going to change this, thanks!

@@ -186,7 +186,7 @@ def update_item_total
end

def persist_totals
order.save!(validate: false)
order.save!(validate: Spree::Config[:run_order_validations_on_order_updater])
Copy link
Member

Choose a reason for hiding this comment

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

Out of curiosity, is there a reason for choosing the [] syntax here?

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right, the . version is the one used in the codebase. Thanks!

Copy link
Member

@jarednorman jarednorman left a comment

Choose a reason for hiding this comment

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

This looks good, though I'm curious about the answers to @spaghetticode's questions.

mamhoff and others added 9 commits June 3, 2020 15:18
Prior to this commit, when running the order updater with invalid
associated records, these records would be saved along with the order.
This updates the order updater such that it actually raises when
called with an invalid order.
This spec would start with an invalid order, which should not happen
in an actual sitation.
We know at this point that adding -1 to the order won't work.

Let's not try.
We know at this point the merged order won't be valid.
Don't persist it.
In this spec, the spec setup assumed that it could get ahead with
a non-persisted store, which never happens IRL.
In real life, completed orders have an email address.
This allows to keep the old behavior and easily switch to the new one.
The default is false, which is what is currently happening.
Also, this commit adds the new default value to the spree.rb
initializer, that will be used when installing new Solidus applications
and to the dummy app that will run specs with the new value set to the
new behavior's value.
The order is not valid without a store and this way the test
is more reliable, it reflects more closely what happens IRL.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_core Changes to the solidus_core gem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants