Skip to content

Commit

Permalink
Merge pull request rails#5049 from fabioyamate/master
Browse files Browse the repository at this point in the history
Fix sanitize_for_mass_assigment when role is nil
  • Loading branch information
José Valim authored and josevalim committed Feb 15, 2012
1 parent 201e67e commit a1b9acb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions activemodel/lib/active_model/mass_assignment_security.rb
Expand Up @@ -224,12 +224,12 @@ def accessible_attributes_configs

protected

def sanitize_for_mass_assignment(attributes, role = :default)
def sanitize_for_mass_assignment(attributes, role = nil)
_mass_assignment_sanitizer.sanitize(attributes, mass_assignment_authorizer(role))
end

def mass_assignment_authorizer(role = :default)
self.class.active_authorizer[role]
def mass_assignment_authorizer(role)
self.class.active_authorizer[role || :default]
end
end
end
7 changes: 7 additions & 0 deletions activemodel/test/cases/mass_assignment_security_test.rb
Expand Up @@ -19,6 +19,13 @@ def test_attribute_protection
assert_equal expected, sanitized
end

def test_attribute_protection_when_role_is_nil
user = User.new
expected = { "name" => "John Smith", "email" => "john@smith.com" }
sanitized = user.sanitize_for_mass_assignment(expected.merge("admin" => true), nil)
assert_equal expected, sanitized
end

def test_only_moderator_role_attribute_accessible
user = SpecialUser.new
expected = { "name" => "John Smith", "email" => "john@smith.com" }
Expand Down

0 comments on commit a1b9acb

Please sign in to comment.