【问题标题】:Params is being nested in params in an Rspec post request参数被嵌套在 Rspec 发布请求中的参数中
【发布时间】:2018-02-26 00:12:51
【问题描述】:

我目前正在使用 Rspec 请求测试嵌套路由的发布请求。

它是这样设置的:

describe 'POST /url_contents' do
  let!(:role) { create(:role, name: "admin") }
  let(:valid_attributes) {
    {
      jwt: "SAMPLE",
      role: role
    }
  }

  context 'when the url is valid' do
    before { post "/#{role.name}/1", params: valid_attributes }

    it 'returns a status code of 201' do
      expect(response).to have_http_status(201)
    end

  end
end

我正在点击我的控制器,但是当我检查参数时,我得到了一个嵌套参数:

:params => { :params => { :jwt => "SAMPLE", :role => #<Role:0x0055959d32a888>" }, "controller"=> "auth"... }

如何让参数指向我的控制器的 :jwt

【问题讨论】:

    标签: rails-activerecord rspec-rails nested-routes


    【解决方案1】:

    我找到了解决方案,但很高兴听到其他想法。

    context 'when the jwt is valid' do
      before { post "/#{role.name}/1", {
        jwt: "SAMPLE",
        role: role
      }
    }
    

    现在 params 没有嵌套。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-08
      • 1970-01-01
      • 2011-12-04
      • 1970-01-01
      • 2013-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多