Skip to content

Commit

Permalink
Permit string and float values in the multiparameter attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelfranca committed Oct 18, 2012
1 parent ae7f109 commit 0c3ca0f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Expand Up @@ -203,7 +203,7 @@ def permit(*filters)
_value = self[filter]
params[filter] = _value unless Hash === _value
end
keys.grep(/\A#{Regexp.escape(filter)}\(\di\)\z/) { |key| params[key] = self[key] }
keys.grep(/\A#{Regexp.escape(filter)}\(\d+[if]?\)\z/) { |key| params[key] = self[key] }
when Hash then
self.slice(*filter.keys).each do |key, values|
return unless values
Expand Down
Expand Up @@ -5,18 +5,20 @@ class MultiParameterAttributesTest < ActiveSupport::TestCase
test "permitted multi-parameter attribute keys" do
params = ActionController::Parameters.new({
book: {
"shipped_at(1i)" => "2012",
"shipped_at(2i)" => "3",
"shipped_at(3i)" => "25",
"shipped_at(4i)" => "10",
"shipped_at(5i)" => "15",
"published_at(1i)" => "1999",
"published_at(2i)" => "2",
"published_at(3i)" => "5"
"shipped_at(1i)" => "2012",
"shipped_at(2i)" => "3",
"shipped_at(3i)" => "25",
"shipped_at(4i)" => "10",
"shipped_at(5i)" => "15",
"published_at(1i)" => "1999",
"published_at(2i)" => "2",
"published_at(3i)" => "5",
"price(1)" => "R$",
"price(2f)" => "2.02"
}
})

permitted = params.permit book: [ :shipped_at ]
permitted = params.permit book: [ :shipped_at, :price ]

assert permitted.permitted?

Expand All @@ -26,6 +28,9 @@ class MultiParameterAttributesTest < ActiveSupport::TestCase
assert_equal "10", permitted[:book]["shipped_at(4i)"]
assert_equal "15", permitted[:book]["shipped_at(5i)"]

assert_equal "R$", permitted[:book]["price(1)"]
assert_equal "2.02", permitted[:book]["price(2f)"]

assert_nil permitted[:book]["published_at(1i)"]
assert_nil permitted[:book]["published_at(2i)"]
assert_nil permitted[:book]["published_at(3i)"]
Expand Down

0 comments on commit 0c3ca0f

Please sign in to comment.