从Rails 4.2.6升级到Rails 5:将{id:2}更改为{params:{id:2}}

时间:2019-06-09 02:19:15

标签: rspec ruby-on-rails-5

当前Rspec代码如下。我知道我需要将{id:2}更改为{params:{id:2}},但是我不确定在下面的共享代码中该怎么做。

shared_examples 'it checks to see if it can be modified' do |method, action|
  let(:params) { defined?(default_params) ? default_params : {} }

  it 'should return error if role does not exist for family' do
    self.send(method, action, params.merge({family_id: @family.id, id: 'invalid_id'}))
    expect(response.body).to eq({errors: ['Role does not exist']}.to_json)
  end

  it 'should not allow user to modify own role' do
    self.send(method, action, params.merge({family_id: @family.id, id: @user.role_for_family(@family).id}))
    expect(response.body).to eq({errors: ["Can't modify your own role"]}.to_json)
  end
end

0 个答案:

没有答案