diff options
Diffstat (limited to 'spec/workers/build_success_worker_spec.rb')
-rw-r--r-- | spec/workers/build_success_worker_spec.rb | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/spec/workers/build_success_worker_spec.rb b/spec/workers/build_success_worker_spec.rb index dba70883130..8e9b178728e 100644 --- a/spec/workers/build_success_worker_spec.rb +++ b/spec/workers/build_success_worker_spec.rb @@ -2,15 +2,39 @@ require 'spec_helper' describe BuildSuccessWorker do describe '#perform' do + subject { described_class.new.perform(build.id) } + + before do + allow_any_instance_of(Deployment).to receive(:create_ref) + end + context 'when build exists' do - context 'when build belogs to the environment' do - let!(:build) { create(:ci_build, environment: 'production') } + context 'when deployment was not created with the build creation' do # An edge case during the transition period + let!(:build) { create(:ci_build, :deploy_to_production) } + + before do + Deployment.delete_all + build.reload + end + + it 'creates a successful deployment' do + expect(build).not_to be_has_deployment + + subject + + build.reload + expect(build).to be_has_deployment + expect(build.deployment).to be_success + end + end + + context 'when deployment was created with the build creation' do # Counter part of the above edge case + let!(:build) { create(:ci_build, :deploy_to_production) } - it 'executes deployment service' do - expect_any_instance_of(CreateDeploymentService) - .to receive(:execute) + it 'does not create a new deployment' do + expect(build).to be_has_deployment - described_class.new.perform(build.id) + expect { subject }.not_to change { Deployment.count } end end @@ -18,10 +42,9 @@ describe BuildSuccessWorker do let!(:build) { create(:ci_build, project: nil) } it 'does not create deployment' do - expect_any_instance_of(CreateDeploymentService) - .not_to receive(:execute) + subject - described_class.new.perform(build.id) + expect(build.reload).not_to be_has_deployment end end end |