Skip to content

Commit 47f0dc5

Browse files
authored
Support enumerization of the same attribute in child class. (#448)
1 parent 594082f commit 47f0dc5

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/enumerize/activerecord.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ def serialize(value)
124124
end
125125

126126
def cast(value)
127+
return value if @subtype.is_a?(Type)
128+
127129
if value.is_a?(::Enumerize::Value)
128130
value
129131
else

test/activerecord_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,15 @@ def self.name
693693
expect(user2.skill).must_equal 'casual'
694694
end
695695

696+
it 'works when child class calls enumerize second time' do
697+
class AdminUser < User
698+
enumerize :account_type, in: [:basic, :premium, :pro]
699+
end
700+
701+
admin = AdminUser.create(account_type: 'pro')
702+
expect(admin.account_type).must_equal 'pro'
703+
end
704+
696705
if Rails::VERSION::MAJOR >= 6
697706
it 'supports AR#insert_all' do
698707
User.delete_all

0 commit comments

Comments
 (0)