Do not process build success if project was removed

This commit is contained in:
Grzegorz Bizon 2016-10-13 14:55:44 +02:00
parent 03a8ed9711
commit 8efa041a73
2 changed files with 15 additions and 2 deletions

View file

@ -4,13 +4,15 @@ class BuildSuccessWorker
def perform(build_id)
Ci::Build.find_by(id: build_id).try do |build|
perform_deloyment(build)
return unless build.project
create_deloyment(build)
end
end
private
def perform_deloyment(build)
def create_deloyment(build)
return if build.environment.blank?
service = CreateDeploymentService.new(

View file

@ -13,6 +13,17 @@ describe BuildSuccessWorker do
described_class.new.perform(build.id)
end
end
context 'when build is not associated with project' do
let!(:build) { create(:ci_build, project: nil) }
it 'does not create deployment' do
expect_any_instance_of(CreateDeploymentService)
.not_to receive(:execute)
described_class.new.perform(build.id)
end
end
end
context 'when build does not exist' do