jeffp / enumerated_attribute

Easy enum for your models, objects and views
MIT License
190 stars 63 forks source link

fix: use values returned by attribute setter methods #64

Open alextk opened 11 years ago

alextk commented 11 years ago

Hi Jeff,

I've discovered extremely annoying bug that is causing active record models to misbehave. If model defines setter methods that change values that are passed, the processed values are reverted back to original values (in new or build assoc methods) by your gem (all logic in setter method is discarded). For example:

class User
  def email=(value)
    value = value.strip
    write_attribute(:email, value)
  end
end

u = User.new(:email => ' asfd@asdf.com ')
u.email  # will return ' asfd@asdf.com ', but should return 'asfd@asdf.com'

Please accept one line fix pull request, which also contains rspec.

Regards, Alex

alextk commented 11 years ago

Also, fixed that keys passed to initialize that aren't really activerecord attributes, will not be converted to attributes.

kianw commented 11 years ago

+1

nchainani commented 8 years ago

+1