当前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