GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Revert "Raise UnknownAttributeError when unknown attributes are supplied 
via mass assignment"

This reverts commit 108db00aa90fe266564483ab301cf0669cae600f.
jeremy (author)
Sat Sep 06 21:01:45 -0700 2008
commit  41efd73887c00ffd228b05d9346ec47a1f3759b9
tree    63dc69da5ab66af9770f14dd4ed2cf011c528fdf
parent  15b1b2b778ce18ff23737b3a0674780d22605fdf
...
122
123
124
125
126
127
128
129
130
131
...
2441
2442
2443
2444
2445
2446
2447
2448
 
2449
2450
2451
...
122
123
124
 
 
 
 
125
126
127
...
2437
2438
2439
 
 
 
 
 
2440
2441
2442
2443
0
@@ -122,10 +122,6 @@ module ActiveRecord #:nodoc:
0
   class MissingAttributeError < NoMethodError
0
   end
0
 
0
- # Raised when unknown attributes are supplied via mass assignment.
0
- class UnknownAttributeError < NoMethodError
0
- end
0
-
0
   # Raised when an error occurred while doing a mass assignment to an attribute through the
0
   # <tt>attributes=</tt> method. The exception has an +attribute+ property that is the name of the
0
   # offending attribute.
0
@@ -2441,11 +2437,7 @@ module ActiveRecord #:nodoc:
0
         attributes = remove_attributes_protected_from_mass_assignment(attributes) if guard_protected_attributes
0
 
0
         attributes.each do |k, v|
0
- if k.include?("(")
0
- multi_parameter_attributes << [ k, v ]
0
- else
0
- respond_to?(:"#{k}=") ? send(:"#{k}=", v) : raise(UnknownAttributeError, "unknown attribute: #{k}")
0
- end
0
+ k.include?("(") ? multi_parameter_attributes << [ k, v ] : send(k + "=", v)
0
         end
0
 
0
         assign_multiparameter_attributes(multi_parameter_attributes)
...
904
905
906
907
908
909
910
911
912
913
914
915
916
917
...
904
905
906
 
 
 
 
 
 
 
 
907
908
909
0
@@ -904,14 +904,6 @@ class BasicsTest < ActiveRecord::TestCase
0
     assert_nil keyboard.id
0
   end
0
 
0
- def test_mass_assigning_invalid_attribute
0
- firm = Firm.new
0
-
0
- assert_raises(ActiveRecord::UnknownAttributeError) do
0
- firm.attributes = { "id" => 5, "type" => "Client", "i_dont_even_exist" => 20 }
0
- end
0
- end
0
-
0
   def test_mass_assignment_protection_on_defaults
0
     firm = Firm.new
0
     firm.attributes = { "id" => 5, "type" => "Client" }

Comments

  • 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.