debian-mirror-gitlab/spec/workers/build_success_worker_spec.rb

76 lines
2.1 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
2016-11-03 12:29:30 +05:30
require 'spec_helper'
describe BuildSuccessWorker do
describe '#perform' do
2018-12-13 13:39:08 +05:30
subject { described_class.new.perform(build.id) }
before do
allow_any_instance_of(Deployment).to receive(:create_ref)
end
2016-11-03 12:29:30 +05:30
context 'when build exists' do
2018-12-13 13:39:08 +05:30
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
2019-07-31 22:56:46 +05:30
allow(Deployments::FinishedWorker).to receive(:perform_async)
2018-12-13 13:39:08 +05:30
Deployment.delete_all
build.reload
end
2016-11-03 12:29:30 +05:30
2018-12-13 13:39:08 +05:30
it 'creates a successful deployment' do
expect(build).not_to be_has_deployment
2016-11-03 12:29:30 +05:30
2018-12-13 13:39:08 +05:30
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 'does not create a new deployment' do
expect(build).to be_has_deployment
expect { subject }.not_to change { Deployment.count }
2016-11-03 12:29:30 +05:30
end
end
context 'when build is not associated with project' do
let!(:build) { create(:ci_build, project: nil) }
it 'does not create deployment' do
2018-12-13 13:39:08 +05:30
subject
expect(build.reload).not_to be_has_deployment
end
end
context 'when the build will stop an environment' do
let!(:build) { create(:ci_build, :stop_review_app, environment: environment.name, project: environment.project) }
let(:environment) { create(:environment, state: :available) }
it 'stops the environment' do
expect(environment).to be_available
subject
2016-11-03 12:29:30 +05:30
2018-12-13 13:39:08 +05:30
expect(environment.reload).to be_stopped
2016-11-03 12:29:30 +05:30
end
end
end
context 'when build does not exist' do
it 'does not raise exception' do
expect { described_class.new.perform(123) }
.not_to raise_error
end
end
end
end