email_address icon indicating copy to clipboard operation
email_address copied to clipboard

EmailAddress::ActiveRecordValidator does not work with ActiveStore

Open opensourceame opened this issue 1 year ago • 0 comments

If you use Active Record Store to store attributes in a serialized field, the ActiveRecordValidator does not work. This is because the validator tries to get the value of the field from accessing it as a hash instead of calling the AR method.

https://github.com/afair/email_address/blob/master/lib/email_address/active_record_validator.rb#L39

Consider this scenario:

class MyClass < ActiveRecord::Base
  self.abstract_class = true
  store_accessor :config
  
  validates_with EmailAddress::ActiveRecordValidator, field: :support_email
end

> a = MyClass.new
> a.support_email = 'invalid email'
> a.support_email
'invalid email'
> a.valid?
true

I made a PR to fix this, in the hopes that someone can review and approve it soon.

opensourceame avatar Mar 19 '25 07:03 opensourceame