提交 00f08793 编写于 作者: A Aaron Patterson

dup strings on return so that in place modifications do not break anything. I...

dup strings on return so that in place modifications do not break anything.  I am looking at you "compute_table_name"
上级 c834a751
......@@ -109,7 +109,7 @@ def define_attr_method(name, value=nil, &block)
# use eval instead of a block to work around a memory leak in dev
# mode in fcgi
value = value.nil? ? 'nil' : value.to_s
sing.send(:define_method, name) { value }
sing.send(:define_method, name) { value.dup }
end
end
......
......@@ -9,6 +9,10 @@ class << self
define_method(:bar) do
'original bar'
end
define_method(:zomg) do
'original zomg'
end
end
def attributes
......@@ -98,6 +102,13 @@ class AttributeMethodsTest < ActiveModel::TestCase
assert_equal "value of foo bar", ModelWithAttributesWithSpaces.new.send(:'foo bar')
end
def test_defined_methods_always_return_duped_string
ModelWithAttributes.define_attr_method(:zomg, 'lol')
assert_equal 'lol', ModelWithAttributes.zomg
ModelWithAttributes.zomg << 'bbq'
assert_equal 'lol', ModelWithAttributes.zomg
end
test '#define_attr_method generates attribute method' do
ModelWithAttributes.define_attr_method(:bar, 'bar')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册