aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/attribute_methods_test.rb
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-12-23 18:20:35 +0000
committerJon Leighton <j@jonathanleighton.com>2011-12-23 18:20:35 +0000
commitf1eb98f0fcca49c3f26a905a5c7b656ea22269d1 (patch)
treeed2f04d48d1894a9dd79de5b596ef3d9a49f7d36 /activerecord/test/cases/attribute_methods_test.rb
parent30ce084bbfbdc4ba877349af4964445cf16295ce (diff)
downloadrails-f1eb98f0fcca49c3f26a905a5c7b656ea22269d1.tar.gz
rails-f1eb98f0fcca49c3f26a905a5c7b656ea22269d1.tar.bz2
rails-f1eb98f0fcca49c3f26a905a5c7b656ea22269d1.zip
Fix #4046.
Diffstat (limited to 'activerecord/test/cases/attribute_methods_test.rb')
-rw-r--r--activerecord/test/cases/attribute_methods_test.rb20
1 files changed, 20 insertions, 0 deletions
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)