Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Kill the whiny_protected_attributes setting and kill the exception ra…

…ised. 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
  • Loading branch information...
commit b318134c99dc3f0f639f6dd225bfc807b4e76460 1 parent 21350d2
@dhh dhh authored
View
2  activerecord/CHANGELOG
@@ -82,7 +82,7 @@
* validates_uniqueness_of behaves well with abstract superclasses and
single-table inheritance. #3833, #9886 [Gabriel Gironda, rramdas, François Beausoleil, Josh Peek, Tarmo Tänav, pat]
-* Raise ProtectedAttributeAssignmentError in development and test environments when mass-assigning to an attr_protected attribute. #9802 [Henrik N]
+* Warn about protected attribute assigments in development and test environments when mass-assigning to an attr_protected attribute. #9802 [Henrik N]
* Speedup database date/time parsing. [Jeremy Kemper, Tarmo Tänav]
View
14 activerecord/lib/active_record/base.rb
@@ -35,8 +35,6 @@ class ReadOnlyRecord < ActiveRecordError #:nodoc:
end
class Rollback < ActiveRecordError #:nodoc:
end
- class ProtectedAttributeAssignmentError < ActiveRecordError #:nodoc:
- end
class DangerousAttributeError < ActiveRecordError #:nodoc:
end
@@ -359,11 +357,6 @@ def self.reset_subclasses #:nodoc:
cattr_accessor :schema_format , :instance_writer => false
@@schema_format = :ruby
- # Determines whether to raise an exception on mass-assignment to protected
- # attributes. Defaults to true.
- cattr_accessor :whiny_protected_attributes, :instance_writer => false
- @@whiny_protected_attributes = true
-
class << self # Class methods
# Find operates with three different retrieval approaches:
#
@@ -2101,12 +2094,7 @@ def remove_attributes_protected_from_mass_assignment(attributes)
removed_attributes = attributes.keys - safe_attributes.keys
if removed_attributes.any?
- error_message = "Can't mass-assign these protected attributes: #{removed_attributes.join(', ')}"
- if self.class.whiny_protected_attributes
- raise ProtectedAttributeAssignmentError, error_message
- else
- logger.error error_message
- end
+ logger.debug "WARNING: Can't mass-assign these protected attributes: #{removed_attributes.join(', ')}"
end
safe_attributes
View
18 activerecord/test/base_test.rb
@@ -67,13 +67,6 @@ class TopicWithProtectedContentAndAccessibleAuthorName < ActiveRecord::Base
class BasicsTest < Test::Unit::TestCase
fixtures :topics, :companies, :developers, :projects, :computers, :accounts, :minimalistics
- # whiny_protected_attributes is turned off since several tests were
- # not written with it in mind, and would otherwise raise exceptions
- # as an irrelevant side-effect.
- def setup
- ActiveRecord::Base.whiny_protected_attributes = false
- end
-
def test_table_exists
assert !NonExistentTable.table_exists?
assert Topic.table_exists?
@@ -861,17 +854,6 @@ def test_mass_assignment_protection_inheritance
assert_equal [ :name, :address, :phone_number ], TightDescendant.accessible_attributes
end
- def test_whiny_protected_attributes
- ActiveRecord::Base.whiny_protected_attributes = true
- assert_raise(ActiveRecord::ProtectedAttributeAssignmentError) do
- LoosePerson.create!(:administrator => true)
- end
- ActiveRecord::Base.whiny_protected_attributes = false
- assert_nothing_raised do
- LoosePerson.create!(:administrator => true)
- end
- end
-
def test_readonly_attributes
assert_equal [ :title ], ReadonlyTitlePost.readonly_attributes
View
3  railties/environments/production.rb
@@ -16,6 +16,3 @@
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
-
-# Disable raising errors when mass-assigning to a protected attribute
-config.active_record.whiny_protected_attributes = false
Please sign in to comment.
Something went wrong with that request. Please try again.