Permalink
Browse files

Revert "Raise UnknownAttributeError when unknown attributes are suppl…

…ied via mass assignment"

This reverts commit 108db00.
  • Loading branch information...
1 parent 15b1b2b commit 41efd73887c00ffd228b05d9346ec47a1f3759b9 @jeremy jeremy committed Sep 7, 2008
Showing with 1 addition and 17 deletions.
  1. +1 −9 activerecord/lib/active_record/base.rb
  2. +0 −8 activerecord/test/cases/base_test.rb
View
10 activerecord/lib/active_record/base.rb
@@ -122,10 +122,6 @@ class DangerousAttributeError < ActiveRecordError
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 @@ def attributes=(new_attributes, guard_protected_attributes = true)
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)
View
8 activerecord/test/cases/base_test.rb
@@ -904,14 +904,6 @@ def test_customized_primary_key_remains_protected_when_referred_to_as_id
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" }

2 comments on commit 41efd73

@cdb

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
Ruby on Rails member

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

Please sign in to comment.