lundi 21 novembre 2016

Rails controller test: Get with query params aren't encoded properly

I have the following line in my controller test:

get brands_url, params: { test: 1, test2: 2}, as: :json

I want to test the api request brands?test=1?test1=2.

In the controller index method, the params objects ends up looking like:

<ActionController::Parameters {"{\"test\":1,\"test2\":2}"=>nil, "controller"=>"brands", "action"=>"index", "format"=>"json", "brand"=>{}} permitted: false>

The params hash is being converted to json and interpreted as a key.

If I remove the as: :json option, I get what I think should be the expected behaviour:

<ActionController::Parameters {"test"=>"1", "test2"=>"2", "controller"=>"brands", "action"=>"index"} permitted: false>

Any thoughts as to why this is happening?

Aucun commentaire:

Enregistrer un commentaire