public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Search Repo:
Kill the whiny_protected_attributes setting and kill the exception raised. 
Instead, just log the mass-assignment misalignment as a debug warning 
(closes #9966)

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8120 
5ecf4fe2-1ee6-0310-87b1-e25e094e27de
dhh (author)
Fri Nov 09 11:57:24 -0800 2007
commit  b318134c99dc3f0f639f6dd225bfc807b4e76460
tree    bc29e9329aee0fb65b077811d30ee1150f556b58
parent  21350d226e525a70a29076b65455193a0255a5c3
...
82
83
84
85
 
86
87
88
...
82
83
84
 
85
86
87
88
0
@@ -82,7 +82,7 @@
0
 * validates_uniqueness_of behaves well with abstract superclasses and
0
 single-table inheritance. #3833, #9886 [Gabriel Gironda, rramdas, François Beausoleil, Josh Peek, Tarmo Tänav, pat]
0
 
0
-* Raise ProtectedAttributeAssignmentError in development and test environments when mass-assigning to an attr_protected attribute. #9802 [Henrik N]
0
+* Warn about protected attribute assigments in development and test environments when mass-assigning to an attr_protected attribute. #9802 [Henrik N]
0
 
0
 * Speedup database date/time parsing. [Jeremy Kemper, Tarmo Tänav]
0
 
...
35
36
37
38
39
40
41
42
...
359
360
361
362
363
364
365
366
367
368
369
...
2101
2102
2103
2104
2105
2106
2107
2108
2109
 
2110
2111
2112
...
35
36
37
 
 
38
39
40
...
357
358
359
 
 
 
 
 
360
361
362
...
2094
2095
2096
 
 
 
 
 
 
2097
2098
2099
2100
0
@@ -35,8 +35,6 @@
0
   end
0
   class Rollback < ActiveRecordError #:nodoc:
0
   end
0
- class ProtectedAttributeAssignmentError < ActiveRecordError #:nodoc:
0
- end
0
   class DangerousAttributeError < ActiveRecordError #:nodoc:
0
   end
0
 
0
@@ -359,11 +357,6 @@
0
     cattr_accessor :schema_format , :instance_writer => false
0
     @@schema_format = :ruby
0
 
0
- # Determines whether to raise an exception on mass-assignment to protected
0
- # attributes. Defaults to true.
0
- cattr_accessor :whiny_protected_attributes, :instance_writer => false
0
- @@whiny_protected_attributes = true
0
-
0
     class << self # Class methods
0
       # Find operates with three different retrieval approaches:
0
       #
0
@@ -2101,12 +2094,7 @@
0
         removed_attributes = attributes.keys - safe_attributes.keys
0
 
0
         if removed_attributes.any?
0
- error_message = "Can't mass-assign these protected attributes: #{removed_attributes.join(', ')}"
0
- if self.class.whiny_protected_attributes
0
- raise ProtectedAttributeAssignmentError, error_message
0
- else
0
- logger.error error_message
0
- end
0
+ logger.debug "WARNING: Can't mass-assign these protected attributes: #{removed_attributes.join(', ')}"
0
         end
0
 
0
         safe_attributes
...
67
68
69
70
71
72
73
74
75
76
77
78
79
...
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
...
67
68
69
 
 
 
 
 
 
 
70
71
72
...
854
855
856
 
 
 
 
 
 
 
 
 
 
 
857
858
859
0
@@ -67,13 +67,6 @@
0
 class BasicsTest < Test::Unit::TestCase
0
   fixtures :topics, :companies, :developers, :projects, :computers, :accounts, :minimalistics
0
 
0
- # whiny_protected_attributes is turned off since several tests were
0
- # not written with it in mind, and would otherwise raise exceptions
0
- # as an irrelevant side-effect.
0
- def setup
0
- ActiveRecord::Base.whiny_protected_attributes = false
0
- end
0
-
0
   def test_table_exists
0
     assert !NonExistentTable.table_exists?
0
     assert Topic.table_exists?
0
@@ -861,17 +854,6 @@
0
     assert_equal [ :name, :address, :phone_number ], TightDescendant.accessible_attributes
0
   end
0
   
0
- def test_whiny_protected_attributes
0
- ActiveRecord::Base.whiny_protected_attributes = true
0
- assert_raise(ActiveRecord::ProtectedAttributeAssignmentError) do
0
- LoosePerson.create!(:administrator => true)
0
- end
0
- ActiveRecord::Base.whiny_protected_attributes = false
0
- assert_nothing_raised do
0
- LoosePerson.create!(:administrator => true)
0
- end
0
- end
0
-
0
   def test_readonly_attributes
0
     assert_equal [ :title ], ReadonlyTitlePost.readonly_attributes
0
     
...
16
17
18
19
20
21
...
16
17
18
 
 
 
0
@@ -16,7 +16,4 @@
0
 
0
 # Disable delivery errors, bad email addresses will be ignored
0
 # config.action_mailer.raise_delivery_errors = false
0
-
0
-# Disable raising errors when mass-assigning to a protected attribute
0
-config.active_record.whiny_protected_attributes = false

Comments

    No one has commented yet.