-
-
Notifications
You must be signed in to change notification settings - Fork 909
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 normalize
matcher
#1558
Add normalize
matcher
#1558
Conversation
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.
Hey @stephannv, I think this is a great idea! I would probably suggest that we extract adding Rails 7.1 to another PR as it may cause CI failures. As for whether we should handle the apply_to_nil
option by adding another method or not, I think we should keep it simple and stick to from
and to
like you've done here.
One thing about this is that we might want to implement a negative version of the matcher. Every matcher can be executed via should_not
, and that may match or may not match, just as with should
. We might want to have another failure message in that case.
Other than that this looks great!
c10b031
to
4e3f6b9
Compare
Done @mcmire . Can you take a look again? I tried to create another PR focused on adding Rails 7.1 to pipeline but I faced some issues, I will give another try later. |
Any updates on this PR? |
@Sub-Xaero I was waiting 7.1 release to update this PR, but I think I don't need to wait. |
@Sub-Xaero I remember now, this PR is waiting |
4e3f6b9
to
b824485
Compare
1c6bacb
to
0188a17
Compare
Hi @matsales28 , are you the new code owner for this PR? I rebased it with main, I think it's ready for review now. Your feedback will be very much appreciated. |
Yes, I'll look at this PR next week. I'm pretty busy at the moment with all the holidays. |
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.
Overall it looks good to me. Left some small suggestions but once adjusted we're ready to merge. One thing that could make it even better is when we're dealing with several attributes, it would be awesome if we could check all of them and then provide an error message listing all the attributes that didn't pass the normalization. Right now, the way it's set up, only the first one that doesn't meet the criteria shows up in the error message. We can make this on an next PR.
spec/unit/shoulda/matchers/active_record/normalize_matcher_spec.rb
Outdated
Show resolved
Hide resolved
0188a17
to
132c3c6
Compare
Yeah @matsales28 , I think it would be a great improvement. Thanks for the feedback, I think I addressed everything. Let me know if I'm missing something. |
spec/unit/shoulda/matchers/active_record/normalize_matcher_spec.rb
Outdated
Show resolved
Hide resolved
spec/unit/shoulda/matchers/active_record/normalize_matcher_spec.rb
Outdated
Show resolved
Hide resolved
spec/unit/shoulda/matchers/active_record/normalize_matcher_spec.rb
Outdated
Show resolved
Hide resolved
spec/unit/shoulda/matchers/active_record/normalize_matcher_spec.rb
Outdated
Show resolved
Hide resolved
132c3c6
to
3e35b4c
Compare
3e35b4c
to
8169b29
Compare
Sorry for that @matsales28 , I think it's working now. |
Why
Rails 7.1 adds
normalizes
API.I think would be nice to shoulda-matchers to have a matchers to easily test the new
normalizes
API, similar toallow_value
/allow_values
matchers. I'm using on my project and this:Will become this:
What do you think about? This PR makes sense?
Some considerations:
normalize(attr)
,from(value)
andto(value)
, I'm open to change.normalizes
acceptsapply_to_nil
option, but I think this should be tested in its own spec, like