diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-04-11 22:21:14 -0400 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-04-18 17:33:25 -0400 |
commit | 29333ddb69e69d0fa99a66bf5fab333e8c5611aa (patch) | |
tree | 02123cb8db76390151f057b4fa85fa73a832b059 /actionpack/test | |
parent | af878151dbf93fae647ec682d96c0caaeb9a81f1 (diff) | |
download | rails-29333ddb69e69d0fa99a66bf5fab333e8c5611aa.tar.gz rails-29333ddb69e69d0fa99a66bf5fab333e8c5611aa.tar.bz2 rails-29333ddb69e69d0fa99a66bf5fab333e8c5611aa.zip |
Implement ActionController::Parameters#to_query and #to_param
Previously it was raising an error because it may be unsafe to use those
methods in a unpermitted parameter. Now we delegate to to_h that already
raise an error when the Parameters instance is not permitted.
This also fix a bug when using `#to_query` in a hash that contains a
`ActionController::Parameters` instance and was returning the name of the
class in the string.
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/controller/required_params_test.rb | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/actionpack/test/controller/required_params_test.rb b/actionpack/test/controller/required_params_test.rb index dd07c2486b..46bb374b3f 100644 --- a/actionpack/test/controller/required_params_test.rb +++ b/actionpack/test/controller/required_params_test.rb @@ -72,9 +72,27 @@ class ParametersRequireTest < ActiveSupport::TestCase assert params.value?("cinco") end - test "to_query is not supported" do - assert_raises(NoMethodError) do - ActionController::Parameters.new(foo: "bar").to_param + test "to_param works like in a Hash" do + params = ActionController::Parameters.new(nested: { key: "value" }).permit! + assert_equal({ nested: { key: "value" } }.to_param, params.to_param) + + params = { root: ActionController::Parameters.new(nested: { key: "value" }).permit! } + assert_equal({ root: { nested: { key: "value" } } }.to_param, params.to_param) + + assert_raise(ActionController::UnfilteredParameters) do + ActionController::Parameters.new(nested: { key: "value" }).to_param + end + end + + test "to_query works like in a Hash" do + params = ActionController::Parameters.new(nested: { key: "value" }).permit! + assert_equal({ nested: { key: "value" } }.to_query, params.to_query) + + params = { root: ActionController::Parameters.new(nested: { key: "value" }).permit! } + assert_equal({ root: { nested: { key: "value" } } }.to_query, params.to_query) + + assert_raise(ActionController::UnfilteredParameters) do + ActionController::Parameters.new(nested: { key: "value" }).to_query end end end |