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:22:44 +0000 |
commit | 7bb754eaedcc49d7b085e417e741d42bb603e4c0 (patch) | |
tree | 837002d6f0c2ed38631063e3ae6628cb3ae91e20 /activerecord/test/cases/attribute_methods_test.rb | |
parent | 6b9ab88a48c9625737a5603a0ac5dc60c25a88d9 (diff) | |
download | rails-7bb754eaedcc49d7b085e417e741d42bb603e4c0.tar.gz rails-7bb754eaedcc49d7b085e417e741d42bb603e4c0.tar.bz2 rails-7bb754eaedcc49d7b085e417e741d42bb603e4c0.zip |
Fix #4046.
Diffstat (limited to 'activerecord/test/cases/attribute_methods_test.rb')
-rw-r--r-- | activerecord/test/cases/attribute_methods_test.rb | 20 |
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 39e58559b0..d51a940d63 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) |