aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-03-17 10:26:11 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-03-17 10:26:11 -0700
commit00f08793677a164bd728a6576e20241697e61c35 (patch)
tree04b1f14ef9aa7140fa46a99898aa454386c08481 /activemodel/test
parentc834a751d2acbd55b580cbba2e96dd29c5d9a452 (diff)
downloadrails-00f08793677a164bd728a6576e20241697e61c35.tar.gz
rails-00f08793677a164bd728a6576e20241697e61c35.tar.bz2
rails-00f08793677a164bd728a6576e20241697e61c35.zip
dup strings on return so that in place modifications do not break anything. I am looking at you "compute_table_name"
Diffstat (limited to 'activemodel/test')
-rw-r--r--activemodel/test/cases/attribute_methods_test.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/activemodel/test/cases/attribute_methods_test.rb b/activemodel/test/cases/attribute_methods_test.rb
index 5cf905bc1f..7fa5a2a7d7 100644
--- a/activemodel/test/cases/attribute_methods_test.rb
+++ b/activemodel/test/cases/attribute_methods_test.rb
@@ -9,6 +9,10 @@ class ModelWithAttributes
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')