diff options
author | Matija Čupić <matteeyah@gmail.com> | 2018-01-15 01:11:38 +0300 |
---|---|---|
committer | Matija Čupić <matteeyah@gmail.com> | 2018-01-15 01:14:11 +0300 |
commit | 091187962372673f0fa7c6f3a0e66cb14bc1b097 (patch) | |
tree | 44138f0c68ef3a07f1acf7e4d6b7673d8ec95e7a /spec/requests/api | |
parent | c9840842f181904e7a94946066bb5ca98c1f657a (diff) |
Add N+1 query spec for Jobs API
Diffstat (limited to 'spec/requests/api')
-rw-r--r-- | spec/requests/api/jobs_spec.rb | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/spec/requests/api/jobs_spec.rb b/spec/requests/api/jobs_spec.rb index 805496e4a54..5def049a669 100644 --- a/spec/requests/api/jobs_spec.rb +++ b/spec/requests/api/jobs_spec.rb @@ -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 |