【发布时间】:2016-11-23 05:22:19
【问题描述】:
我的控制器测试中有以下行:
get brands_url, params: { test: 1, test2: 2}, as: :json
我要测试api请求brands?test=1&test1=2。
在控制器索引方法中,params 对象最终看起来像:
<ActionController::Parameters {"{\"test\":1,\"test2\":2}"=>nil, "controller"=>"brands", "action"=>"index", "format"=>"json", "brand"=>{}} permitted: false>
params 哈希正在被转换为 json 并被解释为一个键。
如果我删除 as: :json 选项,我会得到我认为应该是预期的行为:
<ActionController::Parameters {"test"=>"1", "test2"=>"2", "controller"=>"brands", "action"=>"index"} permitted: false>
对为什么会发生这种情况有任何想法吗?
【问题讨论】:
标签: testing controller ruby-on-rails-5