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

Deprecate raising an exception when order and line item currencies mismatch #3456

Merged

Conversation

kennyadsl
Copy link
Member

@kennyadsl kennyadsl commented Dec 13, 2019

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 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 the type:enhancement Proposed or newly added feature label Dec 13, 2019
@kennyadsl kennyadsl self-assigned this Dec 13, 2019
@kennyadsl kennyadsl force-pushed the kennyadsl/fix-passing-options-to-line-items branch from adb7849 to d4df556 Compare December 13, 2019 14:57
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 kennyadsl force-pushed the kennyadsl/fix-passing-options-to-line-items branch from d4df556 to d19edf1 Compare January 15, 2020 14:47
Copy link
Member

@aldesantis aldesantis left a 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!

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.

@kennyadsl thank you! 🎉

@kennyadsl kennyadsl merged commit c66b685 into solidusio:master Jan 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:enhancement Proposed or newly added feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants