aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/attribute_methods_test.rb
diff options
context:
space:
mode:
authorGodfrey Chan <godfreykfc@gmail.com>2014-08-11 00:00:23 -0700
committerGodfrey Chan <godfreykfc@gmail.com>2014-08-11 00:00:23 -0700
commit2638d5c72444db1dc73c0593cb35f9916fc6284c (patch)
tree818b67e8e5574d88d0b312be04532b549fee2ed0 /activerecord/test/cases/attribute_methods_test.rb
parent49798b52bfaaa452f1c535ca932cc267482348fe (diff)
downloadrails-2638d5c72444db1dc73c0593cb35f9916fc6284c.tar.gz
rails-2638d5c72444db1dc73c0593cb35f9916fc6284c.tar.bz2
rails-2638d5c72444db1dc73c0593cb35f9916fc6284c.zip
Fixed issue w/custom accessors + reserved name + inheritance
Fixed an issue where custom accessor methods (such as those generated by `enum`) with the same name as a global method are incorrectly overridden when subclassing. This was partially fixed in 4155431 then broken again by e5f15a8. Fixes #16288.
Diffstat (limited to 'activerecord/test/cases/attribute_methods_test.rb')
-rw-r--r--activerecord/test/cases/attribute_methods_test.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb
index ab67cf4085..2c07b5cbad 100644
--- a/activerecord/test/cases/attribute_methods_test.rb
+++ b/activerecord/test/cases/attribute_methods_test.rb
@@ -810,6 +810,24 @@ class AttributeMethodsTest < ActiveRecord::TestCase
assert_equal "lol", topic.author_name
end
+ def test_inherited_custom_accessors_with_reserved_names
+ klass = Class.new(ActiveRecord::Base) do
+ self.table_name = 'computers'
+ self.abstract_class = true
+ def system; "omg"; end
+ def system=(val); self.developer = val; end
+ end
+
+ subklass = Class.new(klass)
+ [klass, subklass].each(&:define_attribute_methods)
+
+ computer = subklass.find(1)
+ assert_equal "omg", computer.system
+
+ computer.developer = 99
+ assert_equal 99, computer.developer
+ end
+
def test_on_the_fly_super_invokable_generated_attribute_methods_via_method_missing
klass = new_topic_like_ar_class do
def title