我必须在获取端点中更改admin_serializer
的位置,这会导致规范出现无法解释的问题。
获取端点
get do
scoped_collection = admin_serialize(scope_admin_resource(filter(Campaign.all)))
paginate(filter(sort(scoped_collection)))
end
我已更改为
get do
scoped_collection = scope_admin_resource(filter(Campaign.all))
admin_serialize paginate(filter(sort(scoped_collection))), include: %i[campaign_codes]
end
规格:
let(:parsed_body) { JSON.parse(response.body) }
describe 'GET /api/v1/admin/campaigns' do
subject(:call_endpoint) { get('/api/v1/admin/campaigns', params: params, headers: headers) }
let(:params) { {} }
context 'when request is authorized' do
let(:headers) { authorization_header }
it 'returns Campaign list' do
call_endpoint
expect(parsed_body['data'].first['type']).to eq('campaign')
expect(parsed_body['data'].size).to eq(2)
end
end
end
奇怪的是我的规范因错误而失败:
失败/错误:paginate(filter(sort(scoped_collection)))
NoMethodError: #Hash:0x00007fa7a4344c68的未定义方法'model'
说实话,我不知道发生了什么。应用程序在本地环境中运行良好,只有规范失败。