From 48b6bacbc534d4be3fa89bc19ea83c357a20e598 Mon Sep 17 00:00:00 2001 From: Edouard CHIN Date: Tue, 10 Jul 2018 22:34:02 -0400 Subject: e4e1b62 broke `to_param` handling: - There was an issue inside controller tests where order params were not respected, the reason was because we were calling `Hash#to_query` which sorts the results lexicographically. 1e4e1b62 fixed that issue by not using `to_query` but instead a utility function provided by rack. - However with the fix came another issue where it's now no longer possible to do this ``` post :foo, params: { user: User.first } # Prior to the patch the controller will receive { "user" => "1" } # Whereas now you get { "user": "#" } ``` The fix in this PR is to modify `Hash#to_query` to sort only when it doesn't contain an array structure that looks something like "bar[]" Ref https://github.com/rails/rails/pull/33341#issuecomment-404039396 --- actionpack/test/controller/test_case_test.rb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/test_case_test.rb b/actionpack/test/controller/test_case_test.rb index 663832e9bb..2d0b6cd602 100644 --- a/actionpack/test/controller/test_case_test.rb +++ b/actionpack/test/controller/test_case_test.rb @@ -220,7 +220,7 @@ XML params = Hash[:page, { name: "page name" }, "some key", 123] post :render_raw_post, params: params.dup - assert_equal Rack::Utils.build_nested_query(params), @response.body + assert_equal params.to_query, @response.body end def test_params_round_trip @@ -231,12 +231,25 @@ XML assert_equal params.merge(controller_info), JSON.parse(@response.body) end + def test_handle_to_params + klass = Class.new do + def to_param + "bar" + end + end + + post :test_params, params: { foo: klass.new } + + assert_equal JSON.parse(@response.body)["foo"], "bar" + end + + def test_body_stream params = Hash[:page, { name: "page name" }, "some key", 123] post :render_body, params: params.dup - assert_equal Rack::Utils.build_nested_query(params), @response.body + assert_equal params.to_query, @response.body end def test_document_body_and_params_with_post -- cgit v1.2.3