diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-10-07 19:43:19 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-10-07 19:43:19 +0000 |
commit | 84a14f262031d5081e34559bb1ba52e75b05afb4 (patch) | |
tree | 3de6969180a597d144f4b25a405fe6364323b446 /activerecord/test | |
parent | d9f3c435f907b8097669a7f2c923f731837fb045 (diff) | |
download | rails-84a14f262031d5081e34559bb1ba52e75b05afb4.tar.gz rails-84a14f262031d5081e34559bb1ba52e75b05afb4.tar.bz2 rails-84a14f262031d5081e34559bb1ba52e75b05afb4.zip |
Raise ProtectedAttributeAssignmentError in development and test environments when mass-assigning to an attr_protected attribute. Closes #9699.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7777 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rwxr-xr-x | activerecord/test/base_test.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb index 53ef4a5e86..650d87f91f 100755 --- a/activerecord/test/base_test.rb +++ b/activerecord/test/base_test.rb @@ -67,6 +67,13 @@ 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? @@ -860,6 +867,17 @@ 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 |