Using AppleID causes ActiveModel email validations in my app to fail
oliverswitzer opened this issue · 1 comments
After installing the applie_id gem, I ran my test suite and noticed many failures around email validation.
Error:
EmailValidatorTest#test_: EmailValidator should not allow :email to be ‹"foo@abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.abc.com"›. :
NoMethodError: undefined method `negative_failure_message' for #<Shoulda::Matchers::ActiveModel::AllowValueMatcher:0x00007fdf70118080>
-e:1:in `<main>'
bin/rails test ~/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/shoulda-context-1.2.2/lib/shoulda/context/context.rb:360
After inspecting the Gemfile.lock, I noticed this dependency hierarchy:
apple_id (0.3.0)
openid_connect (~> 1.1.7)
validate_email
I took a look at the validate_email
gem repo, and it looks to me like this gem takes the liberty of defining an ActiveModel::EachValidator. This means that any model in my application that has declared the following validation:
validates :email, email: true
Will now use the EmailValidator
defined by the validate_email
gem instead of the one we have declared in our own codebase, which happens to have the same name.
The untrue, rails still does not have email validation out of the box.validate_email
gem also appears to have been a shim for Rails 3 when (perhaps) this sort of validation did not come out of the box?
Request:
Can we remove this dependency from the no longer the right solution . Please read comment below.openid_connect
connect gem and default to using standard active model validations? Otherwise this will unfortunately not allow me to take advantage of this very useful gem.
Update:
- first off, wanted to apologize for not doing prior research about whether or not active model had any out-of-the-box email validations. It looks like it still does not, for whatever reason.
- secondly, I managed to fix this issue by renaming the custom
EmailValidator
in our codebase (a class that inherits and from and implementsActiveModel::EachValidator
) to something that does not conflict with theEmailValidator
that thevalidate_email
gem defines. This seemed to make the issue go away for me.
What has puzzled me about this issue is that ActiveModel would allow a 3rd party gem to add validations to your Rails app. Seems very strange and potentially dangerous.
Truthfully this feels like an issue that I should open up with the maintainers of ActiveModel instead of with you. Apologies! I will close this issue.