Add N+1 query spec for Jobs API

This commit is contained in:
Matija Čupić 2018-01-14 23:11:38 +01:00
parent c9840842f1
commit 0911879623
No known key found for this signature in database
GPG key ID: 4BAF84FFACD2E5DE

View file

@ -25,8 +25,10 @@ describe API::Jobs do
describe 'GET /projects/:id/jobs' do
let(:query) { Hash.new }
before do
get api("/projects/#{project.id}/jobs", api_user), query
before do |example|
unless example.metadata[:skip_before_request]
get api("/projects/#{project.id}/jobs", api_user), query
end
end
context 'authorized user' do
@ -51,6 +53,12 @@ describe API::Jobs do
expect(json_job['pipeline']['status']).to eq job.pipeline.status
end
it 'avoids N+1 queries', skip_before_request: true do
control_count = ActiveRecord::QueryRecorder.new { go }.count
create_list(:ci_build, 5, pipeline: pipeline)
expect { go }.not_to exceed_query_limit(control_count)
end
context 'filter project with one scope element' do
let(:query) { { 'scope' => 'pending' } }
@ -83,6 +91,9 @@ describe API::Jobs do
expect(response).to have_gitlab_http_status(401)
end
end
def go
get api("/projects/#{project.id}/jobs", api_user), query
end
end
describe 'GET /projects/:id/pipelines/:pipeline_id/jobs' do