diff --git a/activerecord/lib/active_record/attribute_assignment.rb b/activerecord/lib/active_record/attribute_assignment.rb index 30fa2c8ba5f..86e0842e3bf 100644 --- a/activerecord/lib/active_record/attribute_assignment.rb +++ b/activerecord/lib/active_record/attribute_assignment.rb @@ -43,7 +43,7 @@ module ActiveRecord def _assign_attribute(k, v) public_send("#{k}=", v) - rescue NoMethodError + rescue NoMethodError, NameError if respond_to?("#{k}=") raise else diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb index 5feea1e7ddc..a1c59098f00 100644 --- a/activerecord/test/cases/attribute_methods_test.rb +++ b/activerecord/test/cases/attribute_methods_test.rb @@ -728,6 +728,17 @@ class AttributeMethodsTest < ActiveRecord::TestCase assert "unknown attribute: hello", error.message end + # This test is related to a bug in Ruby 2.2.1. + # It can be safely removed once that bug is fixed. + # + # xref: https://bugs.ruby-lang.org/issues/10969 + def test_bulk_does_not_raise_name_error + nope rescue nil # necessary to trigger the bug + assert_raises(ActiveRecord::UnknownAttributeError) { + Topic.new(hello: "world") + } + end + def test_methods_override_in_multi_level_subclass klass = Class.new(Developer) do def name