mirror of https://github.com/rails/rails
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:
parent
a616b1e523
commit
46f0be2276
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue