enumerize icon indicating copy to clipboard operation
enumerize copied to clipboard

ActiveRecord _was method on integer enumerize attribute in child class is not returning enumerize value

Open tr4b4nt opened this issue 11 months ago • 0 comments

Simple way to reproduce it is with following test in this repository:

    class User < ActiveRecord::Base
      enumerize :status, :in => { active: 1, blocked: 2 }, scope: true
   end
...
    it 'has correct value in _was attribute in child class' do
      class AdminUser < User
        enumerize :status, :in => { active: 1, blocked: 2, inactive: 3 }, scope: true
      end

      admin = AdminUser.create(status: 'active')
      admin.update status: 'blocked'
      expect(admin.status_was).must_equal 'active'
    end

admin.status_was was returning "blocked" as Enumerize::Value before fix in https://github.com/brainspec/enumerize/pull/448. Now it returns 2 (as Integer).

I looked at the code but could not figure out how to fix this without breaking the mentioned fix. I will probably try more some time later when I have time again. Or if you could point me to the right direction I would be happy to prepare PR.

tr4b4nt avatar Jan 29 '25 18:01 tr4b4nt