diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/import_export/all_models.yml | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/import_export/safe_model_attributes.yml | 1 | ||||
-rw-r--r-- | spec/models/ci/pipeline_spec.rb | 37 | ||||
-rw-r--r-- | spec/models/commit_status_spec.rb | 26 | ||||
-rw-r--r-- | spec/presenters/ci/build_presenter_spec.rb | 34 | ||||
-rw-r--r-- | spec/presenters/ci/pipeline_presenter_spec.rb | 2 |
6 files changed, 81 insertions, 21 deletions
diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index 8aa8e3fc1cd..5f3a83d5792 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -91,10 +91,12 @@ pipelines: - trigger_requests - auto_canceled_by - auto_canceled_pipelines +- auto_canceled_jobs statuses: - project - pipeline - user +- auto_canceled_by variables: - project triggers: diff --git a/spec/lib/gitlab/import_export/safe_model_attributes.yml b/spec/lib/gitlab/import_export/safe_model_attributes.yml index 15b8fa07040..50154a67908 100644 --- a/spec/lib/gitlab/import_export/safe_model_attributes.yml +++ b/spec/lib/gitlab/import_export/safe_model_attributes.yml @@ -224,6 +224,7 @@ CommitStatus: - token - lock_version - coverage_regex +- auto_canceled_by_id Ci::Variable: - id - project_id diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 38d3be926aa..3595601a72d 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -136,6 +136,43 @@ describe Ci::Pipeline, models: true do end end + describe '#auto_canceled?' do + subject { pipeline.auto_canceled? } + + context 'when it is canceled' do + before do + pipeline.cancel + end + + context 'when there is auto_canceled_by' do + before do + pipeline.update(auto_canceled_by: create(:ci_empty_pipeline)) + end + + it 'is auto canceled' do + is_expected.to be_truthy + end + end + + context 'when there is no auto_canceled_by' do + it 'is not auto canceled' do + is_expected.to be_falsey + end + end + + context 'when it is retried and canceled manually' do + before do + pipeline.enqueue + pipeline.cancel + end + + it 'is not auto canceled' do + is_expected.to be_falsey + end + end + end + end + describe 'pipeline stages' do before do create(:commit_status, pipeline: pipeline, diff --git a/spec/models/commit_status_spec.rb b/spec/models/commit_status_spec.rb index 7343b735a74..3bffb8dba72 100644 --- a/spec/models/commit_status_spec.rb +++ b/spec/models/commit_status_spec.rb @@ -101,6 +101,32 @@ describe CommitStatus, :models do end end + describe '#auto_canceled?' do + subject { commit_status.auto_canceled? } + + context 'when it is canceled' do + before do + commit_status.cancel + end + + context 'when there is auto_canceled_by' do + before do + commit_status.update(auto_cancel_by: create(:ci_empty_pipeline)) + end + + it 'is auto canceled' do + is_expected.to be_truthy + end + end + + context 'when there is no auto_canceled_by' do + it 'is not auto canceled' do + is_expected.to be_falsey + end + end + end + end + describe '#duration' do subject { commit_status.duration } diff --git a/spec/presenters/ci/build_presenter_spec.rb b/spec/presenters/ci/build_presenter_spec.rb index a9a8df1550d..ebb599bb48c 100644 --- a/spec/presenters/ci/build_presenter_spec.rb +++ b/spec/presenters/ci/build_presenter_spec.rb @@ -58,33 +58,27 @@ describe Ci::BuildPresenter do end describe '#status_title' do - context 'when build is canceled' do + context 'when build is auto-canceled' do before do - expect(presenter).to receive(:canceled?).and_return(true) + expect(build).to receive(:auto_canceled?).and_return(true) + expect(build).to receive(:auto_canceled_by_id).and_return(1) end - context 'when pipeline is auto-canceled' do - before do - expect(pipeline).to receive(:auto_canceled?).and_return(true) - expect(pipeline).to receive(:auto_canceled_by_id).and_return(1) - end + it 'shows that the job is auto-canceled' do + status_title = presenter.status_title - it 'shows that the job is auto-canceled' do - status_title = presenter.status_title - - expect(status_title).to include('auto-canceled') - expect(status_title).to include('Pipeline #1') - end + expect(status_title).to include('auto-canceled') + expect(status_title).to include('Pipeline #1') end + end - context 'when pipeline is not auto-canceled' do - before do - expect(pipeline).to receive(:auto_canceled?).and_return(false) - end + context 'when build is not auto-canceled' do + before do + expect(build).to receive(:auto_canceled?).and_return(false) + end - it 'shows that the job is auto-canceled' do - expect(presenter.status_title).to be_nil - end + it 'does not have a status title' do + expect(presenter.status_title).to be_nil end end end diff --git a/spec/presenters/ci/pipeline_presenter_spec.rb b/spec/presenters/ci/pipeline_presenter_spec.rb index 449e45c1f4c..9134d1cc31c 100644 --- a/spec/presenters/ci/pipeline_presenter_spec.rb +++ b/spec/presenters/ci/pipeline_presenter_spec.rb @@ -46,7 +46,7 @@ describe Ci::PipelinePresenter do expect(pipeline).to receive(:auto_canceled?).and_return(false) end - it 'shows that the job is auto-canceled' do + it 'does not have a status title' do expect(presenter.status_title).to be_nil end end |