Skip to content

Commit

Permalink
fix AR 3.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
lest committed Feb 8, 2012
1 parent b56183e commit 6a3d5b2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/enumerize/integrations/basic.rb
Expand Up @@ -37,8 +37,8 @@ def #{attr.name}_text
def _define_enumerize_attribute(mod, attr)
mod.module_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{attr.name}
if defined?(super)
self.class.#{attr.name}.find_value(super)
if respond_to?(:read_attribute, true)
self.class.#{attr.name}.find_value(read_attribute(:#{attr.name}))
else
if defined?(@#{attr.name})
self.class.#{attr.name}.find_value(@#{attr.name})
Expand All @@ -49,8 +49,8 @@ def #{attr.name}
end
def #{attr.name}=(new_value)
if defined?(super)
super self.class.#{attr.name}.find_value(new_value).to_s
if respond_to?(:write_attribute, true)
write_attribute :#{attr.name}, self.class.#{attr.name}.find_value(new_value).to_s
else
@#{attr.name} = self.class.#{attr.name}.find_value(new_value).to_s
end
Expand Down
1 change: 1 addition & 0 deletions test/activerecord_test.rb
Expand Up @@ -49,5 +49,6 @@ class User < ActiveRecord::Base

it 'has default value' do
User.new.role.must_equal 'user'
User.new.attributes['role'].must_equal 'user'
end
end

0 comments on commit 6a3d5b2

Please sign in to comment.