-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Deprecate raising an exception when order and line item currencies mismatch #3456
Merged
kennyadsl
merged 4 commits into
solidusio:master
from
nebulab:kennyadsl/fix-passing-options-to-line-items
Jan 28, 2020
Merged
Deprecate raising an exception when order and line item currencies mismatch #3456
kennyadsl
merged 4 commits into
solidusio:master
from
nebulab:kennyadsl/fix-passing-options-to-line-items
Jan 28, 2020
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
houndci-bot
reviewed
Dec 13, 2019
kennyadsl
force-pushed
the
kennyadsl/fix-passing-options-to-line-items
branch
from
December 13, 2019 14:57
adb7849
to
d4df556
Compare
aldesantis
requested changes
Dec 13, 2019
core/lib/generators/spree/install/templates/config/initializers/spree.rb.tt
Show resolved
Hide resolved
The current behavior is to raise an exception when the currency of the price that we are trying to set on a line item mismatches with the order currency. However, this is creating issues because it's raising also when the currency is valid. This happens because we don't have control of the order used by Rails to set attributes on the LineItem instance and order is still nil/uset when money_price= is executed. This commit allows to conditionally avoid the raise, switching the behavior to a standard Rails validation. This is better because at validation time, we have the instance with all the attributes set and we are sure to be able to perform the right check. The validation behavior will become the default with future commits and the raise bahavior will be deprecated.
This ensures that the DummyApp that we use for specs and new applications will use the new default behavior, while preserving the old behavior for existing applications that are just upgrading. Setting this new default for the DummyApp allows us to restore a pending spec that was skipped for the inconsistent raise behavior that we want to deprecate.
Now that we have a validation in place we should let users change the error message in their language. For the exception, we always print the error with English locale.
This is done into an initializer to be sure users will look at this deprecation warning, even if the exception is not raised.
kennyadsl
force-pushed
the
kennyadsl/fix-passing-options-to-line-items
branch
from
January 15, 2020 14:47
d4df556
to
d19edf1
Compare
aldesantis
approved these changes
Jan 15, 2020
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.
@kennyadsl looking great, thank you!
spaghetticode
approved these changes
Jan 21, 2020
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.
@kennyadsl thank you! 🎉
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The current behavior is to raise an exception when the currency of the price that we are trying to set on a line item mismatches with the order currency.
However, this is creating issues because it's raising also when the currency is valid. This happens because we don't have control of the order used by Rails to set attributes on the LineItem instance and
order is still nil/unset when
money_price=
is executed.This PR allows to conditionally avoid the raise, switching the behavior to a standard Rails validation. This is better because, at validation time, we have the instance with all the attributes set and we are sure to be able to perform the right check.
The validation behavior is the new default for new installations and the
raise
behavior has been deprecated.This PR has the side effect to restore passing the
options
attribute to a line_item to set attributes that are needed for pricing changes. We had this feature broken (with pending tests) since a past security change.Checklist:
[ ] I have updated Guides and README accordingly to this change (if needed)[ ] I have attached screenshots to this PR for visual changes (if needed)