Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tr4b4nt opened this issue Jan 29, 2025 · 0 comments

Comments

@tr4b4nt
Copy link

tr4b4nt commented Jan 29, 2025

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 #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant