diff options
author | r7kamura <r7kamura@gmail.com> | 2018-12-18 18:34:14 +0900 |
---|---|---|
committer | r7kamura <r7kamura@gmail.com> | 2018-12-18 21:44:05 +0900 |
commit | eb37fd0aec4fdc5122ceeb8a56b1e9b0cb5e3b76 (patch) | |
tree | 513e3ed4140f2f59c398524945fa8ea49a539b1d | |
parent | d99984d48c6eeb105c5edd1c142834a5c770f499 (diff) | |
download | rails-eb37fd0aec4fdc5122ceeb8a56b1e9b0cb5e3b76.tar.gz rails-eb37fd0aec4fdc5122ceeb8a56b1e9b0cb5e3b76.tar.bz2 rails-eb37fd0aec4fdc5122ceeb8a56b1e9b0cb5e3b76.zip |
Allow nil params on controller HTTP test methods
-rw-r--r-- | actionpack/CHANGELOG.md | 4 | ||||
-rw-r--r-- | actionpack/lib/action_controller/test_case.rb | 4 | ||||
-rw-r--r-- | actionpack/test/controller/test_case_test.rb | 12 |
3 files changed, 18 insertions, 2 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 13fbbafc0c..04b479106d 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,3 +1,7 @@ +* Allow nil params on controller HTTP test methods + + *Ryo Nakamura* + * Introduce ActionDispatch::HostAuthorization This is a new middleware that guards against DNS rebinding attacks by diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 5d784ceb31..a643484d96 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -457,7 +457,7 @@ module ActionController # respectively which will make tests more expressive. # # Note that the request method is not verified. - def process(action, method: "GET", params: {}, session: nil, body: nil, flash: {}, format: nil, xhr: false, as: nil) + def process(action, method: "GET", params: nil, session: nil, body: nil, flash: {}, format: nil, xhr: false, as: nil) check_required_ivars http_method = method.to_s.upcase @@ -485,7 +485,7 @@ module ActionController format ||= as end - parameters = params.symbolize_keys + parameters = (params || {}).symbolize_keys if format parameters[:format] = format diff --git a/actionpack/test/controller/test_case_test.rb b/actionpack/test/controller/test_case_test.rb index c931e2daac..bc64135589 100644 --- a/actionpack/test/controller/test_case_test.rb +++ b/actionpack/test/controller/test_case_test.rb @@ -478,6 +478,18 @@ XML ) end + def test_nil_params + get :test_params, params: nil + parsed_params = JSON.parse(@response.body) + assert_equal( + { + "action" => "test_params", + "controller" => "test_case_test/test" + }, + parsed_params + ) + end + def test_query_param_named_action get :test_query_parameters, params: { action: "foobar" } parsed_params = JSON.parse(@response.body) |