Commit 0320517d authored by Gregor Schmidt's avatar Gregor Schmidt

[#282] Make safe_attributes work with symbol keys

parent b5b36844
...@@ -67,7 +67,7 @@ module Redmine ...@@ -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 ...@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment