mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
define_attr_method should be able to define methods that returns nil
This commit is contained in:
parent
4532b39f5f
commit
445241d713
2 changed files with 4 additions and 2 deletions
|
@ -106,8 +106,8 @@ module ActiveModel
|
|||
if block_given?
|
||||
sing.send :define_method, name, &block
|
||||
else
|
||||
value = value.nil? ? 'nil' : value.to_s
|
||||
sing.send(:define_method, name) { value.dup }
|
||||
value = value.to_s if value
|
||||
sing.send(:define_method, name) { value && value.dup }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -115,6 +115,8 @@ class AttributeMethodsTest < ActiveModel::TestCase
|
|||
assert_respond_to ModelWithAttributes, :bar
|
||||
assert_equal "original bar", ModelWithAttributes.original_bar
|
||||
assert_equal "bar", ModelWithAttributes.bar
|
||||
ModelWithAttributes.define_attr_method(:bar)
|
||||
assert !ModelWithAttributes.bar
|
||||
end
|
||||
|
||||
test '#define_attr_method generates attribute method with invalid identifier characters' do
|
||||
|
|
Loading…
Reference in a new issue