Skip to content

Commit

Permalink
Revert "Raise UnknownAttributeError when unknown attributes are suppl…
Browse files Browse the repository at this point in the history
…ied via mass assignment"

This reverts commit 108db00.
  • Loading branch information
jeremy committed Sep 7, 2008
1 parent 15b1b2b commit 41efd73
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 17 deletions.
10 changes: 1 addition & 9 deletions activerecord/lib/active_record/base.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ class DangerousAttributeError < ActiveRecordError
class MissingAttributeError < NoMethodError class MissingAttributeError < NoMethodError
end 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 # 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 # <tt>attributes=</tt> method. The exception has an +attribute+ property that is the name of the
# offending attribute. # offending attribute.
Expand Down Expand Up @@ -2441,11 +2437,7 @@ def attributes=(new_attributes, guard_protected_attributes = true)
attributes = remove_attributes_protected_from_mass_assignment(attributes) if guard_protected_attributes attributes = remove_attributes_protected_from_mass_assignment(attributes) if guard_protected_attributes


attributes.each do |k, v| attributes.each do |k, v|
if k.include?("(") k.include?("(") ? multi_parameter_attributes << [ k, v ] : send(k + "=", v)
multi_parameter_attributes << [ k, v ]
else
respond_to?(:"#{k}=") ? send(:"#{k}=", v) : raise(UnknownAttributeError, "unknown attribute: #{k}")
end
end end


assign_multiparameter_attributes(multi_parameter_attributes) assign_multiparameter_attributes(multi_parameter_attributes)
Expand Down
8 changes: 0 additions & 8 deletions activerecord/test/cases/base_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -904,14 +904,6 @@ def test_customized_primary_key_remains_protected_when_referred_to_as_id
assert_nil keyboard.id assert_nil keyboard.id
end 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 def test_mass_assignment_protection_on_defaults
firm = Firm.new firm = Firm.new
firm.attributes = { "id" => 5, "type" => "Client" } firm.attributes = { "id" => 5, "type" => "Client" }
Expand Down

2 comments on commit 41efd73

@cdb
Copy link

@cdb cdb commented on 41efd73 Sep 16, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t really know where to put this comment (sorry), but it’s a bit related to this. The test on line 493 of activerecord/test/cases/base_test.rb (test_initialize_with_invalid_attribute) doesn’t fail when I think it should, because as far as I can tell now entering February 31 (invalid date) now saves as March 2 instead of raising a MultiparameterAssignmentErrors. I’m not sure when this changed or not.

Unless I’m mis-reading the test, it seems like it doesn’t fail because the rescue is never called, and so neither are the asserts. It should probably be an assert_raises….

let me know if there’s a better place to put this comment.

@lifo
Copy link
Member

@lifo lifo commented on 41efd73 Sep 16, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cdb You can try mailing http://groups.google.com/group/rubyonrails-core

Please sign in to comment.