Permalink
Browse files

Merge pull request #14345 from arthurnn/revert_14052

Fixes STI when 2+ levels deep.
  • Loading branch information...
2 parents 6868265 + e5f15a8 commit ccaf0ed791d69567f91a659c9efc7d3bb5bc8b3b @chancancode chancancode committed Mar 11, 2014
@@ -105,9 +105,9 @@ def instance_method_already_implemented?(method_name)
super
else
# If B < A and A defines its own attribute method, then we don't want to overwrite that.
- defined = method_defined_within?(method_name, superclass) &&
- superclass.instance_method(method_name).owner != superclass.generated_attribute_methods
- defined || super
+ defined = method_defined_within?(method_name, superclass, superclass.generated_attribute_methods)
+ base_defined = Base.method_defined?(method_name) || Base.private_method_defined?(method_name)
+ defined && !base_defined || super
end
end
@@ -746,6 +746,19 @@ def test_bulk_update_raise_unknown_attribute_errro
assert "unknown attribute: hello", error.message
end
+ def test_methods_override_in_multi_level_subclass
+ klass = Class.new(Developer) do
+ def name
+ "dev:#{read_attribute(:name)}"
+ end
+ end
+
+ 2.times { klass = Class.new klass }
+ dev = klass.new(name: 'arthurnn')
+ dev.save!
+ assert_equal 'dev:arthurnn', dev.reload.name
+ end
+
def test_global_methods_are_overwritten
klass = Class.new(ActiveRecord::Base) do
self.table_name = 'computers'

0 comments on commit ccaf0ed

Please sign in to comment.