diff options
author | Alexander Uvarov <alexander.uvarov@gmail.com> | 2011-06-23 12:56:39 +0600 |
---|---|---|
committer | Alexander Uvarov <alexander.uvarov@gmail.com> | 2011-06-23 12:56:39 +0600 |
commit | 528f405cdc6195f0a872431fdcd2529729e27af8 (patch) | |
tree | f97ba9085011666a8d29011b1f8416d867893193 /activemodel/test | |
parent | 87b548ccac8fd9b384a024a1374a2474e7c4d604 (diff) | |
download | rails-528f405cdc6195f0a872431fdcd2529729e27af8.tar.gz rails-528f405cdc6195f0a872431fdcd2529729e27af8.tar.bz2 rails-528f405cdc6195f0a872431fdcd2529729e27af8.zip |
Allow to specify mass-assignment roles as array
Diffstat (limited to 'activemodel/test')
-rw-r--r-- | activemodel/test/cases/mass_assignment_security_test.rb | 14 | ||||
-rw-r--r-- | activemodel/test/models/mass_assignment_specific.rb | 10 |
2 files changed, 23 insertions, 1 deletions
diff --git a/activemodel/test/cases/mass_assignment_security_test.rb b/activemodel/test/cases/mass_assignment_security_test.rb index a778240827..be07e59a2f 100644 --- a/activemodel/test/cases/mass_assignment_security_test.rb +++ b/activemodel/test/cases/mass_assignment_security_test.rb @@ -43,6 +43,20 @@ class MassAssignmentSecurityTest < ActiveModel::TestCase assert_equal expected, sanitized end + def test_attributes_accessible_with_roles_given_as_array + user = Account.new + expected = { "name" => "John Smith", "email" => "john@smith.com" } + sanitized = user.sanitize_for_mass_assignment(expected.merge("admin" => true)) + assert_equal expected, sanitized + end + + def test_attributes_accessible_with_admin_role_when_roles_given_as_array + user = Account.new + expected = { "name" => "John Smith", "email" => "john@smith.com", "admin" => true } + sanitized = user.sanitize_for_mass_assignment(expected.merge("super_powers" => true), :admin) + assert_equal expected, sanitized + end + def test_attributes_protected_by_default firm = Firm.new expected = { } diff --git a/activemodel/test/models/mass_assignment_specific.rb b/activemodel/test/models/mass_assignment_specific.rb index 53b37369ff..1d123fa58c 100644 --- a/activemodel/test/models/mass_assignment_specific.rb +++ b/activemodel/test/models/mass_assignment_specific.rb @@ -20,6 +20,14 @@ class Person public :sanitize_for_mass_assignment end +class Account + include ActiveModel::MassAssignmentSecurity + attr_accessible :name, :email, :as => [:default, :admin] + attr_accessible :admin, :as => :admin + + public :sanitize_for_mass_assignment +end + class Firm include ActiveModel::MassAssignmentSecurity @@ -65,4 +73,4 @@ end class TightDescendant < TightPerson attr_accessible :phone_number attr_accessible :super_powers, :as => :admin -end
\ No newline at end of file +end |