Permalink
Browse files

Permit string and float values in the multiparameter attributes

  • Loading branch information...
1 parent ae7f109 commit 0c3ca0f013904d40bf11ac9da95ed0ef3d9ddc86 @rafaelfranca rafaelfranca committed Oct 18, 2012
@@ -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
@@ -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?
@@ -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)"]

0 comments on commit 0c3ca0f

Please sign in to comment.