diff options
Diffstat (limited to 'spec/workers/ci/initial_pipeline_process_worker_spec.rb')
-rw-r--r-- | spec/workers/ci/initial_pipeline_process_worker_spec.rb | 58 |
1 files changed, 53 insertions, 5 deletions
diff --git a/spec/workers/ci/initial_pipeline_process_worker_spec.rb b/spec/workers/ci/initial_pipeline_process_worker_spec.rb index 5fb8671fd5c..c7bbe83433e 100644 --- a/spec/workers/ci/initial_pipeline_process_worker_spec.rb +++ b/spec/workers/ci/initial_pipeline_process_worker_spec.rb @@ -2,12 +2,13 @@ require 'spec_helper' -RSpec.describe Ci::InitialPipelineProcessWorker do - describe '#perform' do - let_it_be_with_reload(:pipeline) do - create(:ci_pipeline, :with_job, status: :created) - end +RSpec.describe Ci::InitialPipelineProcessWorker, feature_category: :continuous_integration do + let_it_be(:project) { create(:project, :repository) } + let(:job) { build(:ci_build, project: project) } + let(:stage) { build(:ci_stage, project: project, statuses: [job]) } + let(:pipeline) { create(:ci_pipeline, stages: [stage], status: :created, project: project, builds: [job]) } + describe '#perform' do include_examples 'an idempotent worker' do let(:job_args) { pipeline.id } @@ -19,5 +20,52 @@ RSpec.describe Ci::InitialPipelineProcessWorker do expect(pipeline.reload).to be_pending end end + + context 'when a pipeline does not contain a deployment job' do + it 'does not create any deployments' do + expect { subject }.not_to change { Deployment.count } + end + end + + context 'when a pipeline contains a teardown job' do + let(:job) { build(:ci_build, :stop_review_app, project: project) } + + before do + create(:environment, name: job.expanded_environment_name) + end + + it 'does not create a deployment record' do + expect { subject }.not_to change { Deployment.count } + + expect(job.deployment).to be_nil + end + end + + context 'when a pipeline contains a deployment job' do + let(:job) { build(:ci_build, :start_review_app, project: project) } + let!(:environment) { create(:environment, project: project, name: job.expanded_environment_name) } + + it 'creates a deployment record' do + expect { subject }.to change { Deployment.count }.by(1) + + expect(job.deployment).to have_attributes( + project: job.project, + ref: job.ref, + sha: job.sha, + deployable: job, + deployable_type: 'CommitStatus', + environment: job.persisted_environment) + end + + context 'when the corresponding environment does not exist' do + let(:environment) {} + + it 'does not create a deployment record' do + expect { subject }.not_to change { Deployment.count } + + expect(job.deployment).to be_nil + end + end + end end end |