diff options
author | Tom Stuart <tom@experthuman.com> | 2012-01-11 09:57:21 +0000 |
---|---|---|
committer | Tom Stuart <tom@experthuman.com> | 2012-01-11 09:57:21 +0000 |
commit | 701afabd3d025ecca987c94b7b94dc93ef80ccfc (patch) | |
tree | b379e1e77f825c1d79971e1be5f2a3d97ce7e26b /activerecord/test | |
parent | d0acd025ec47488d3b6d1f3f8c731ad9036d359e (diff) | |
download | rails-701afabd3d025ecca987c94b7b94dc93ef80ccfc.tar.gz rails-701afabd3d025ecca987c94b7b94dc93ef80ccfc.tar.bz2 rails-701afabd3d025ecca987c94b7b94dc93ef80ccfc.zip |
Test that #[] and #[]= keep working when #read_attribute and #write_attribute are overridden
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/attribute_methods_test.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb index 398aa8e28a..d6de668a17 100644 --- a/activerecord/test/cases/attribute_methods_test.rb +++ b/activerecord/test/cases/attribute_methods_test.rb @@ -318,6 +318,39 @@ class AttributeMethodsTest < ActiveRecord::TestCase # puts "" end + def test_overridden_write_attribute + topic = Topic.new + def topic.write_attribute(attr_name, value) + super(attr_name, value.downcase) + end + + topic.send(:write_attribute, :title, "Yet another topic") + assert_equal "yet another topic", topic.title + + topic[:title] = "Yet another topic: part 2" + assert_equal "yet another topic: part 2", topic.title + + topic.send(:write_attribute, "title", "Yet another topic: part 3") + assert_equal "yet another topic: part 3", topic.title + + topic["title"] = "Yet another topic: part 4" + assert_equal "yet another topic: part 4", topic.title + end + + def test_overridden_read_attribute + topic = Topic.new + topic.title = "Stop changing the topic" + def topic.read_attribute(attr_name) + super(attr_name).upcase + end + + assert_equal "STOP CHANGING THE TOPIC", topic.send(:read_attribute, "title") + assert_equal "STOP CHANGING THE TOPIC", topic["title"] + + assert_equal "STOP CHANGING THE TOPIC", topic.send(:read_attribute, :title) + assert_equal "STOP CHANGING THE TOPIC", topic[:title] + end + def test_read_overridden_attribute topic = Topic.new(:title => 'a') def topic.title() 'b' end |