[#282] Make safe_attributes work with symbol keys
This commit is contained in:
parent
b5b3684473
commit
0320517d2c
@ -67,7 +67,7 @@ module Redmine
|
|||||||
# # => {'title' => 'My book'}
|
# # => {'title' => 'My book'}
|
||||||
def delete_unsafe_attributes(attrs, user=User.current)
|
def delete_unsafe_attributes(attrs, user=User.current)
|
||||||
safe = safe_attribute_names(user)
|
safe = safe_attribute_names(user)
|
||||||
attrs.dup.delete_if {|k,v| !safe.include?(k)}
|
attrs.dup.delete_if {|k,v| !safe.include?(k.to_s)}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Sets attributes from attrs that are safe
|
# Sets attributes from attrs that are safe
|
||||||
|
@ -90,6 +90,13 @@ class Redmine::SafeAttributesTest < ActiveSupport::TestCase
|
|||||||
assert_equal 'jsmith', p.login
|
assert_equal 'jsmith', p.login
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_with_indifferent_access
|
||||||
|
p = Person.new
|
||||||
|
p.safe_attributes = {'firstname' => 'Jack', :lastname => 'Miller'}
|
||||||
|
assert_equal 'Jack', p.firstname
|
||||||
|
assert_equal 'Miller', p.lastname
|
||||||
|
end
|
||||||
|
|
||||||
def test_use_safe_attributes_in_subclasses
|
def test_use_safe_attributes_in_subclasses
|
||||||
b = Book.new
|
b = Book.new
|
||||||
p = PublishedBook.new
|
p = PublishedBook.new
|
||||||
|
Loading…
x
Reference in New Issue
Block a user