From 09daaaa1e0481207c06416f909171d4f66bc0f6d Mon Sep 17 00:00:00 2001 From: Andrew White Date: Sat, 21 May 2011 16:28:11 +0100 Subject: Add support for passing mass assignment roles to dynamic finders. Closes #1170. --- .../test/cases/mass_assignment_security_test.rb | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/mass_assignment_security_test.rb b/activerecord/test/cases/mass_assignment_security_test.rb index 765033852d..33737e12a8 100644 --- a/activerecord/test/cases/mass_assignment_security_test.rb +++ b/activerecord/test/cases/mass_assignment_security_test.rb @@ -239,6 +239,54 @@ class MassAssignmentSecurityTest < ActiveRecord::TestCase end end + def test_find_or_initialize_by_with_attr_accessible_attributes + p = TightPerson.find_or_initialize_by_first_name('Josh', attributes_hash) + + assert_default_attributes(p) + end + + def test_find_or_initialize_by_with_admin_role_with_attr_accessible_attributes + p = TightPerson.find_or_initialize_by_first_name('Josh', attributes_hash, :as => :admin) + + assert_admin_attributes(p) + end + + def test_find_or_initialize_by_with_attr_protected_attributes + p = LoosePerson.find_or_initialize_by_first_name('Josh', attributes_hash) + + assert_default_attributes(p) + end + + def test_find_or_initialize_by_with_admin_role_with_attr_protected_attributes + p = LoosePerson.find_or_initialize_by_first_name('Josh', attributes_hash, :as => :admin) + + assert_admin_attributes(p) + end + + def test_find_or_create_by_with_attr_accessible_attributes + p = TightPerson.find_or_create_by_first_name('Josh', attributes_hash) + + assert_default_attributes(p, true) + end + + def test_find_or_create_by_with_admin_role_with_attr_accessible_attributes + p = TightPerson.find_or_create_by_first_name('Josh', attributes_hash, :as => :admin) + + assert_admin_attributes(p, true) + end + + def test_find_or_create_by_with_attr_protected_attributes + p = LoosePerson.find_or_create_by_first_name('Josh', attributes_hash) + + assert_default_attributes(p, true) + end + + def test_find_or_create_by_with_admin_role_with_attr_protected_attributes + p = LoosePerson.find_or_create_by_first_name('Josh', attributes_hash, :as => :admin) + + assert_admin_attributes(p, true) + end + end -- cgit v1.2.3