Catch possible `NameError` in Ruby 2.2.1. Closes #19297

This patch was necessary due to a bug in Ruby 2.2.1:
https://bugs.ruby-lang.org/issues/10969

A minimal reproduction script can be found here:
https://gist.github.com/senny/9864a138defa322ed807
This commit is contained in:
Yves Senn 2015-03-13 09:19:38 +01:00
parent a616b1e523
commit 46f0be2276
2 changed files with 12 additions and 1 deletions

View File

@ -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

View File

@ -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