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

Document where support for AR normalizes #49105

Merged
merged 1 commit into from
Sep 1, 2023
Merged

Document where support for AR normalizes #49105

merged 1 commit into from
Sep 1, 2023

Conversation

Earlopain
Copy link
Contributor

@Earlopain Earlopain commented Sep 1, 2023

Motivation / Background

Reading through the changelog for normalized made me wonder if it also works with where. It says it works with finder methods, but I don't think where is one of those. It works regardless, so I added it to the changelog and made some tests for it.

I also noticed some inconsistencies in the changelog, fixed those up too. I hope that's ok to put in one PR.

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

Copy link
Member

@akhilgkrishnan akhilgkrishnan left a comment

Choose a reason for hiding this comment

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

@Earlopain Thanks for updating this 👍 . This LGTM after squashing your commits.

Also some other small changelog tweak:
* Add normalize_value_for to the activerecord changelog
* Fix a wrong method reference in the 7.1 release notes
@Earlopain
Copy link
Contributor Author

Done!

@byroot byroot merged commit 9fd3d03 into rails:main Sep 1, 2023
4 checks passed
@Earlopain Earlopain deleted the ar-normalizes-where branch September 1, 2023 17:08
jonathanhefner added a commit that referenced this pull request Sep 10, 2023
In #49105, `where` examples were added to the `normalizes` documentation
to demonstrate that normalizations are also applied for `where`.
However, as with the `exists?` examples, we should also demonstrate that
normalizations are only applied to keyword arguments, not positional
arguments.  We can also address the original source of the confusion by
changing the wording of "finder methods" to "query methods".

This commit also removes the tests added in #49105.  `normalizes` works
at the level of attribute types, so there is no need to test every query
method.  Testing `find_by` is sufficient.  (And, in point of fact,
`find_by` is implemented in terms of `where`.)
@@ -856,6 +856,7 @@
```ruby
class User < ActiveRecord::Base
normalizes :email, with: -> email { email.strip.downcase }
normalizes :phone, with: -> phone { phone.delete("^0-9").delete_prefix("1") }
Copy link
Member

Choose a reason for hiding this comment

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

@Earlopain This example is a little confusing, how about just phone.strip?

Copy link
Member

Choose a reason for hiding this comment

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

D'oh, sorry I was mixing up the previous example because you added the where below 🤦 sorry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants