summaryrefslogtreecommitdiff
path: root/spec/services
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-06-14 14:44:09 +0200
committerKamil Trzcinski <ayufan@ayufan.eu>2016-06-14 14:44:09 +0200
commit6209b60c96d8b380ac184d83647c3c8b0b026cac (patch)
tree76c10929acdac040649188f85d289ab86a87205a /spec/services
parentbb6f246790fb3a6b85ab2fd9341566557da64a23 (diff)
downloadgitlab-ce-6209b60c96d8b380ac184d83647c3c8b0b026cac.tar.gz
Properly create a new deployment after build success
Diffstat (limited to 'spec/services')
-rw-r--r--spec/services/create_deployment_service_spec.rb66
1 files changed, 62 insertions, 4 deletions
diff --git a/spec/services/create_deployment_service_spec.rb b/spec/services/create_deployment_service_spec.rb
index 76f3e0ac9ff..b6ae3505379 100644
--- a/spec/services/create_deployment_service_spec.rb
+++ b/spec/services/create_deployment_service_spec.rb
@@ -1,8 +1,7 @@
require 'spec_helper'
describe CreateDeploymentService, services: true do
- let(:build) { create(:ci_build) }
- let(:project) { build.project }
+ let(:project) { create(:empty_project) }
let(:user) { create(:user) }
let(:service) { described_class.new(project, user, params) }
@@ -11,7 +10,7 @@ describe CreateDeploymentService, services: true do
let(:params) do
{ environment: 'production',
ref: 'master',
- sha: build.sha,
+ sha: '97de212e80737a608d939f648d959671fb0a0142',
}
end
@@ -43,7 +42,7 @@ describe CreateDeploymentService, services: true do
let(:params) do
{ environment: 'name with spaces',
ref: 'master',
- sha: build.sha,
+ sha: '97de212e80737a608d939f648d959671fb0a0142',
}
end
@@ -56,4 +55,63 @@ describe CreateDeploymentService, services: true do
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 }
+ end
+
+ it 'does not create a new deployment' do
+ expect { subject }.not_to change { Deployment.count }
+ end
+
+ it 'does not call a service' do
+ expect_any_instance_of(described_class).not_to receive(:execute)
+ subject
+ end
+ end
+
+ shared_examples 'does create environment and deployment' do
+ it 'does create a new environment' do
+ expect { subject }.to change { Environment.count }.by(1)
+ end
+
+ it 'does create a new deployment' do
+ expect { subject }.to change { Deployment.count }.by(1)
+ end
+
+ it 'does call a service' do
+ expect_any_instance_of(described_class).to receive(:execute)
+ subject
+ end
+ end
+
+ 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') }
+
+ context 'when build succeeds' do
+ it_behaves_like 'does create environment and deployment' do
+ subject { build.success }
+ end
+ end
+
+ context 'when build fails' do
+ it_behaves_like 'does not create environment and deployment' do
+ subject { build.drop }
+ end
+ end
+ end
+ end
end