Add n plus one spec for v3 builds api
This commit is contained in:
parent
74f2f9b30f
commit
7e0849840a
1 changed files with 14 additions and 2 deletions
|
@ -13,10 +13,12 @@ describe API::V3::Builds do
|
|||
describe 'GET /projects/:id/builds ' do
|
||||
let(:query) { '' }
|
||||
|
||||
before do
|
||||
before do |example|
|
||||
create(:ci_build, :skipped, pipeline: pipeline)
|
||||
|
||||
get v3_api("/projects/#{project.id}/builds?#{query}", api_user)
|
||||
unless example.metadata[:skip_before_request]
|
||||
get v3_api("/projects/#{project.id}/builds?#{query}", api_user)
|
||||
end
|
||||
end
|
||||
|
||||
context 'authorized user' do
|
||||
|
@ -40,6 +42,12 @@ describe API::V3::Builds do
|
|||
expect(json_build['pipeline']['status']).to eq build.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' }
|
||||
|
||||
|
@ -84,6 +92,10 @@ describe API::V3::Builds do
|
|||
expect(response).to have_gitlab_http_status(401)
|
||||
end
|
||||
end
|
||||
|
||||
def go
|
||||
get v3_api("/projects/#{project.id}/builds?#{query}", api_user)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET /projects/:id/repository/commits/:sha/builds' do
|
||||
|
|
Loading…
Reference in a new issue