diff options
Diffstat (limited to 'spec/requests/api/ci/jobs_spec.rb')
-rw-r--r-- | spec/requests/api/ci/jobs_spec.rb | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/spec/requests/api/ci/jobs_spec.rb b/spec/requests/api/ci/jobs_spec.rb index 57828e50320..b8983e9632e 100644 --- a/spec/requests/api/ci/jobs_spec.rb +++ b/spec/requests/api/ci/jobs_spec.rb @@ -32,8 +32,7 @@ RSpec.describe API::Ci::Jobs do end let!(:job) do - create(:ci_build, :success, :tags, pipeline: pipeline, - artifacts_expire_at: 1.day.since) + create(:ci_build, :success, :tags, pipeline: pipeline, artifacts_expire_at: 1.day.since) end before do @@ -94,9 +93,13 @@ RSpec.describe API::Ci::Jobs do let(:params_with_token) { {} } end + def perform_request + get api('/job'), headers: headers_with_token, params: params_with_token + end + before do |example| unless example.metadata[:skip_before_request] - get api('/job'), headers: headers_with_token, params: params_with_token + perform_request end end @@ -125,6 +128,15 @@ RSpec.describe API::Ci::Jobs do expect(json_response['finished_at']).to be_nil end + it 'avoids N+1 queries', :skip_before_request do + control_count = ActiveRecord::QueryRecorder.new { perform_request }.count + + running_job = create(:ci_build, :running, project: project, user: user, pipeline: pipeline, artifacts_expire_at: 1.day.since) + running_job.save! + + expect { perform_request }.not_to exceed_query_limit(control_count) + end + it_behaves_like 'returns common pipeline data' do let(:jobx) { running_job } end @@ -237,6 +249,10 @@ RSpec.describe API::Ci::Jobs do it 'includes environment slug' do expect(json_response.dig('environment', 'slug')).to eq('production') end + + it 'includes environment tier' do + expect(json_response.dig('environment', 'tier')).to eq('production') + end end context 'when non-deployment environment action' do @@ -248,6 +264,10 @@ RSpec.describe API::Ci::Jobs do it 'includes environment slug' do expect(json_response.dig('environment', 'slug')).to eq('review') end + + it 'includes environment tier' do + expect(json_response.dig('environment', 'tier')).to eq('development') + end end context 'when passing the token as params' do |