diff options
author | Santiago Pastorino <santiago@wyeworks.com> | 2012-01-11 06:10:22 -0800 |
---|---|---|
committer | Santiago Pastorino <santiago@wyeworks.com> | 2012-01-11 12:10:59 -0200 |
commit | bb78804a5e382bde072186e80062f7df9f20ecc8 (patch) | |
tree | 215195f2b11265372259fb1627d36b6fe10b0406 /activerecord/test | |
parent | 9c88005d9766a853839adbab4acf77660b6cfb8b (diff) | |
download | rails-bb78804a5e382bde072186e80062f7df9f20ecc8.tar.gz rails-bb78804a5e382bde072186e80062f7df9f20ecc8.tar.bz2 rails-bb78804a5e382bde072186e80062f7df9f20ecc8.zip |
Merge pull request #4408 from tomstuart/read-and-write-attribute-aliases
#[] and #[]= are no longer interchangeable with #read_attribute and #write_attribute
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/attribute_methods_test.rb | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb index d51a940d63..0fbe1813fb 100644 --- a/activerecord/test/cases/attribute_methods_test.rb +++ b/activerecord/test/cases/attribute_methods_test.rb @@ -266,8 +266,14 @@ class AttributeMethodsTest < ActiveRecord::TestCase topic.send(:write_attribute, :title, "Still another topic") assert_equal "Still another topic", topic.title - topic.send(:write_attribute, "title", "Still another topic: part 2") + topic[:title] = "Still another topic: part 2" assert_equal "Still another topic: part 2", topic.title + + topic.send(:write_attribute, "title", "Still another topic: part 3") + assert_equal "Still another topic: part 3", topic.title + + topic["title"] = "Still another topic: part 4" + assert_equal "Still another topic: part 4", topic.title end def test_read_attribute @@ -320,6 +326,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 |