diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-12-23 18:20:35 +0000 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-12-23 18:20:35 +0000 |
commit | f1eb98f0fcca49c3f26a905a5c7b656ea22269d1 (patch) | |
tree | ed2f04d48d1894a9dd79de5b596ef3d9a49f7d36 /activerecord/test/cases | |
parent | 30ce084bbfbdc4ba877349af4964445cf16295ce (diff) | |
download | rails-f1eb98f0fcca49c3f26a905a5c7b656ea22269d1.tar.gz rails-f1eb98f0fcca49c3f26a905a5c7b656ea22269d1.tar.bz2 rails-f1eb98f0fcca49c3f26a905a5c7b656ea22269d1.zip |
Fix #4046.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/attribute_methods/read_test.rb | 1 | ||||
-rw-r--r-- | activerecord/test/cases/attribute_methods_test.rb | 20 | ||||
-rw-r--r-- | activerecord/test/cases/base_test.rb | 1 |
3 files changed, 22 insertions, 0 deletions
diff --git a/activerecord/test/cases/attribute_methods/read_test.rb b/activerecord/test/cases/attribute_methods/read_test.rb index 86a240d93c..7665f1c12e 100644 --- a/activerecord/test/cases/attribute_methods/read_test.rb +++ b/activerecord/test/cases/attribute_methods/read_test.rb @@ -14,6 +14,7 @@ module ActiveRecord def setup @klass = Class.new do + def self.superclass; Base; end def self.base_class; self; end include ActiveRecord::AttributeMethods diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb index 8e509a9792..b6cf26f978 100644 --- a/activerecord/test/cases/attribute_methods_test.rb +++ b/activerecord/test/cases/attribute_methods_test.rb @@ -711,6 +711,26 @@ class AttributeMethodsTest < ActiveRecord::TestCase assert_equal nil, Topic.new.read_attribute(nil) end + # If B < A, and A defines an accessor for 'foo', we don't want to override + # that by defining a 'foo' method in the generated methods module for B. + # (That module will be inserted between the two, e.g. [B, <GeneratedAttributes>, A].) + def test_inherited_custom_accessors + klass = Class.new(ActiveRecord::Base) do + self.table_name = "topics" + self.abstract_class = true + def title; "omg"; end + def title=(val); self.author_name = val; end + end + subklass = Class.new(klass) + [klass, subklass].each(&:define_attribute_methods) + + topic = subklass.find(1) + assert_equal "omg", topic.title + + topic.title = "lol" + assert_equal "lol", topic.author_name + end + private def cached_columns @cached_columns ||= time_related_columns_on_topic.map(&:name) diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 433b586971..6ff0c1355c 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -1251,6 +1251,7 @@ class BasicsTest < ActiveRecord::TestCase important_topic.reload assert_equal(hash, important_topic.important) + assert_equal(hash, important_topic.read_attribute(:important)) end def test_serialized_time_attribute |