diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2007-11-09 19:57:24 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2007-11-09 19:57:24 +0000 |
commit | b318134c99dc3f0f639f6dd225bfc807b4e76460 (patch) | |
tree | bc29e9329aee0fb65b077811d30ee1150f556b58 /activerecord | |
parent | 21350d226e525a70a29076b65455193a0255a5c3 (diff) | |
download | rails-b318134c99dc3f0f639f6dd225bfc807b4e76460.tar.gz rails-b318134c99dc3f0f639f6dd225bfc807b4e76460.tar.bz2 rails-b318134c99dc3f0f639f6dd225bfc807b4e76460.zip |
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
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 14 | ||||
-rwxr-xr-x | activerecord/test/base_test.rb | 18 |
3 files changed, 2 insertions, 32 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index c196e24ac7..061fe0f46e 100644 --- a/activerecord/CHANGELOG +++ b/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] diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 3e7fa13e97..991d8b040c 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -35,8 +35,6 @@ module ActiveRecord #:nodoc: end class Rollback < ActiveRecordError #:nodoc: end - class ProtectedAttributeAssignmentError < ActiveRecordError #:nodoc: - end class DangerousAttributeError < ActiveRecordError #:nodoc: end @@ -359,11 +357,6 @@ module ActiveRecord #: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 @@ module ActiveRecord #:nodoc: 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 diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb index 103f9f7271..e17b2a1b57 100755 --- a/activerecord/test/base_test.rb +++ b/activerecord/test/base_test.rb @@ -67,13 +67,6 @@ end 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 @@ class BasicsTest < Test::Unit::TestCase 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 |