Skip to content

Commit

Permalink
Support enumerization of the same attribute in child class. (#448)
Browse files Browse the repository at this point in the history
  • Loading branch information
nashby authored Mar 19, 2024
1 parent 594082f commit 47f0dc5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/enumerize/activerecord.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ def serialize(value)
end

def cast(value)
return value if @subtype.is_a?(Type)

if value.is_a?(::Enumerize::Value)
value
else
Expand Down
9 changes: 9 additions & 0 deletions test/activerecord_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,15 @@ def self.name
expect(user2.skill).must_equal 'casual'
end

it 'works when child class calls enumerize second time' do
class AdminUser < User
enumerize :account_type, in: [:basic, :premium, :pro]
end

admin = AdminUser.create(account_type: 'pro')
expect(admin.account_type).must_equal 'pro'
end

if Rails::VERSION::MAJOR >= 6
it 'supports AR#insert_all' do
User.delete_all
Expand Down

0 comments on commit 47f0dc5

Please sign in to comment.