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

Backport #4228 to V2.11 #4230

Merged
merged 1 commit into from
Jan 5, 2022
Merged

Conversation

jcsanti
Copy link
Contributor

@jcsanti jcsanti commented Dec 27, 2021

Many thanks to @waiting-for-dev & @kennyadsl for the quick review of #4228 🙂🚀

Description

This PR backports #4228 to Solidus 2.11.

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
  • I have attached screenshots to this PR for visual changes (present in original PR)

Promotion codes are always stored in the database in lowercase. Up to
this commit, the transformation of the in-memory value of a code was
performed in a `before_save` callback.

This implementation led to a weird behavior that can easily be
reproduced with a fresh Solidus install:
- create a first promotion, with a single promotion code (e.g. "test")
- attempt to create another promotion, with the exact same value for the
  single promotion code
    => triggers a flash error messages which states "Codes is invalid"
- attempt to re-save the same form, this time with a single promotion
  code with the value "TEST"
    => the page crashes due to an `ActiveRecord::RecordNotUnique` error

The expected error handling would be that any input that would end up
matching an existing code (after having been stripped of spaces &
downcased) should trigger the same flash error rather than crash the
page.

This behavior can be achieved by normalizing values earlier in a
`before_validation` callback: that way, the validation callback will
query the database using a stripped/downcased value and, should a match
be found, set an error on the model instance as expected.
Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

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

Thanks, but if we want to backport I think we also need to do it on 3.0.

@jcsanti
Copy link
Contributor Author

jcsanti commented Dec 27, 2021

Thanks, but if we want to backport I think we also need to do it on 3.0.

My bad, I forgot there already was a new minor version for solidus 3. I'll open another PR right away!

Copy link
Contributor

@waiting-for-dev waiting-for-dev left a comment

Choose a reason for hiding this comment

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

Thanks!

@waiting-for-dev
Copy link
Contributor

We're forgetting the most recent minor version: v3.1. We need to backport there 🙂

@jcsanti
Copy link
Contributor Author

jcsanti commented Jan 3, 2022

We're forgetting the most recent minor version: v3.1. We need to backport there 🙂

Hello @waiting-for-dev, happy New Year!

Here is the PR for 3.1 => #4237 🙂

Copy link
Contributor

@waiting-for-dev waiting-for-dev left a comment

Choose a reason for hiding this comment

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

Thanks! And Happy New Year @jcsanti! 🥳

@waiting-for-dev waiting-for-dev merged commit c728183 into solidusio:v2.11 Jan 5, 2022
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.

None yet

4 participants