Skip to content
Snippets Groups Projects
Commit 3726dc4b authored by Grzegorz Bizon's avatar Grzegorz Bizon
Browse files

Check if project exists before creating deployment

parent 4e934259
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -2,6 +2,8 @@
 
class CreateDeploymentService < BaseService
def execute(deployable = nil)
return unless executable?
ActiveRecord::Base.transaction do
@deployable = deployable
@environment = prepare_environment
Loading
Loading
@@ -14,6 +16,10 @@ def execute(deployable = nil)
 
private
 
def executable?
project && name.present?
end
def deploy
project.deployments.create(
environment: @environment,
Loading
Loading
Loading
Loading
@@ -4,8 +4,6 @@ class BuildSuccessWorker
 
def perform(build_id)
Ci::Build.find_by(id: build_id).try do |build|
return unless build.project
create_deployment(build)
end
end
Loading
Loading
Loading
Loading
@@ -84,11 +84,22 @@
expect(subject).to be_persisted
end
end
context 'when project was removed' do
let(:project) { nil }
it 'does not create deployment or environment' do
expect { subject }.not_to raise_error
expect(Environment.count).to be_zero
expect(Deployment.count).to be_zero
end
end
end
 
describe 'processing of builds' do
let(:environment) { nil }
shared_examples 'does not create environment and deployment' do
it 'does not create a new environment' do
expect { subject }.not_to change { Environment.count }
Loading
Loading
@@ -133,12 +144,12 @@
 
context 'without environment specified' do
let(:build) { create(:ci_build, project: project) }
it_behaves_like 'does not create environment and deployment' do
subject { build.success }
end
end
context 'when environment is specified' do
let(:pipeline) { create(:ci_pipeline, project: project) }
let(:build) { create(:ci_build, pipeline: pipeline, environment: 'production', options: options) }
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment