From 84a14f262031d5081e34559bb1ba52e75b05afb4 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 7 Oct 2007 19:43:19 +0000 Subject: 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 --- activerecord/test/base_test.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'activerecord/test') 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 -- cgit v1.2.3