Skip to content

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

Description

@tr4b4nt

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions