summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatija Čupić <matteeyah@gmail.com>2018-01-13 12:32:26 +0100
committerMatija Čupić <matteeyah@gmail.com>2018-01-13 12:32:26 +0100
commit7e0849840af4625c8ef37621f1ebc1696960be86 (patch)
tree1912fed06a386ca4271eec1782766c1f9b1c01fd
parent74f2f9b30fb1972a26481072486b358eb943309f (diff)
downloadgitlab-ce-7e0849840af4625c8ef37621f1ebc1696960be86.tar.gz
Add n plus one spec for v3 builds api
-rw-r--r--spec/requests/api/v3/builds_spec.rb16
1 files changed, 14 insertions, 2 deletions
diff --git a/spec/requests/api/v3/builds_spec.rb b/spec/requests/api/v3/builds_spec.rb
index a73bb456b52..304d5c3a42f 100644
--- a/spec/requests/api/v3/builds_spec.rb
+++ b/spec/requests/api/v3/builds_spec.rb
@@ -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