lynndylanhurley / lynndylanhurley/devise_token_auth
Why is email uniqueness validation performed in such a strange way?
- Dominant language
- Ruby
- Stars
- 3.6k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
1. I agree with #613 issue - overriding `email_changed?` is risky because this method is a part of `ActiveModel::Dirty`, which could be quite useful.
2. Why do you write your own `unique_email_user` validator for email validation instead of using `ActiveRecord` built-in `UniquenessValidator`? It makes quite inconvenient to, for example, implement uniqueness validation also on update, not only create like it is now. I had to override `unique_email_user` validation method to achieve this:
``` ruby
# here's my implementation of uniqueness validation, working also on update:
validates_uniqueness_of :email, scope: :provider, if: -> { provider == 'email' }
# ...
# and here's the `unique_email_user` method I had to override:
def unique_email_user
true
end
```
Contributor guide
Research direction
Start by reading the unique_email_user validation and the email_changed? behavior referenced in the issue, along with ActiveRecord's UniquenessValidator and issue #613. The work is complete when the project has a decided validation approach, with create and update uniqueness behavior covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rails, ruby
- Domain
- authentication, backend
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100