mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Revert "Raise UnknownAttributeError when unknown attributes are supplied via mass assignment"
This reverts commit 108db00aa9.
This commit is contained in:
@@ -122,10 +122,6 @@ module ActiveRecord #:nodoc:
|
||||
class MissingAttributeError < NoMethodError
|
||||
end
|
||||
|
||||
# Raised when unknown attributes are supplied via mass assignment.
|
||||
class UnknownAttributeError < NoMethodError
|
||||
end
|
||||
|
||||
# Raised when an error occurred while doing a mass assignment to an attribute through the
|
||||
# <tt>attributes=</tt> method. The exception has an +attribute+ property that is the name of the
|
||||
# offending attribute.
|
||||
@@ -2441,11 +2437,7 @@ module ActiveRecord #:nodoc:
|
||||
attributes = remove_attributes_protected_from_mass_assignment(attributes) if guard_protected_attributes
|
||||
|
||||
attributes.each do |k, v|
|
||||
if k.include?("(")
|
||||
multi_parameter_attributes << [ k, v ]
|
||||
else
|
||||
respond_to?(:"#{k}=") ? send(:"#{k}=", v) : raise(UnknownAttributeError, "unknown attribute: #{k}")
|
||||
end
|
||||
k.include?("(") ? multi_parameter_attributes << [ k, v ] : send(k + "=", v)
|
||||
end
|
||||
|
||||
assign_multiparameter_attributes(multi_parameter_attributes)
|
||||
|
||||
@@ -904,14 +904,6 @@ class BasicsTest < ActiveRecord::TestCase
|
||||
assert_nil keyboard.id
|
||||
end
|
||||
|
||||
def test_mass_assigning_invalid_attribute
|
||||
firm = Firm.new
|
||||
|
||||
assert_raises(ActiveRecord::UnknownAttributeError) do
|
||||
firm.attributes = { "id" => 5, "type" => "Client", "i_dont_even_exist" => 20 }
|
||||
end
|
||||
end
|
||||
|
||||
def test_mass_assignment_protection_on_defaults
|
||||
firm = Firm.new
|
||||
firm.attributes = { "id" => 5, "type" => "Client" }
|
||||
|
||||
Reference in New Issue
Block a user