summaryrefslogtreecommitdiff
path: root/spec/services/deployments
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-12-14 15:07:56 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-14 15:07:56 +0000
commit016af097cb1fa872fdc28a786d16315e55cd2701 (patch)
tree76f97f90a8048685efb3eb0c543b3a75d99be6ee /spec/services/deployments
parent00b8ecb72c9f77d864aff3572f028613f45af03c (diff)
downloadgitlab-ce-016af097cb1fa872fdc28a786d16315e55cd2701.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/deployments')
-rw-r--r--spec/services/deployments/create_service_spec.rb87
-rw-r--r--spec/services/deployments/update_service_spec.rb6
2 files changed, 39 insertions, 54 deletions
diff --git a/spec/services/deployments/create_service_spec.rb b/spec/services/deployments/create_service_spec.rb
index e41c8259ea9..6ab1f8635f7 100644
--- a/spec/services/deployments/create_service_spec.rb
+++ b/spec/services/deployments/create_service_spec.rb
@@ -3,67 +3,54 @@
require 'spec_helper'
describe Deployments::CreateService do
- let(:environment) do
- double(
- :environment,
- deployment_platform: double(:platform, cluster_id: 1),
- project_id: 2,
- id: 3
- )
- end
-
- let(:user) { double(:user) }
+ let(:user) { create(:user) }
describe '#execute' do
- let(:service) { described_class.new(environment, user, {}) }
-
- it 'does not run the AfterCreateService service if the deployment is not persisted' do
- deploy = double(:deployment, persisted?: false)
+ let(:project) { create(:project, :repository) }
+ let(:environment) { create(:environment, project: project) }
- expect(service)
- .to receive(:create_deployment)
- .and_return(deploy)
+ it 'creates a deployment' do
+ service = described_class.new(
+ environment,
+ user,
+ sha: 'b83d6e391c22777fca1ed3012fce84f633d7fed0',
+ ref: 'master',
+ tag: false,
+ status: 'success'
+ )
- expect(Deployments::AfterCreateService)
- .not_to receive(:new)
+ expect(Deployments::SuccessWorker).to receive(:perform_async)
+ expect(Deployments::FinishedWorker).to receive(:perform_async)
- expect(service.execute).to eq(deploy)
+ expect(service.execute).to be_persisted
end
- it 'runs the AfterCreateService service if the deployment is persisted' do
- deploy = double(:deployment, persisted?: true)
- after_service = double(:after_create_service)
-
- expect(service)
- .to receive(:create_deployment)
- .and_return(deploy)
-
- expect(Deployments::AfterCreateService)
- .to receive(:new)
- .with(deploy)
- .and_return(after_service)
+ it 'does not change the status if no status is given' do
+ service = described_class.new(
+ environment,
+ user,
+ sha: 'b83d6e391c22777fca1ed3012fce84f633d7fed0',
+ ref: 'master',
+ tag: false
+ )
- expect(after_service)
- .to receive(:execute)
+ expect(Deployments::SuccessWorker).not_to receive(:perform_async)
+ expect(Deployments::FinishedWorker).not_to receive(:perform_async)
- expect(service.execute).to eq(deploy)
+ expect(service.execute).to be_persisted
end
end
- describe '#create_deployment' do
- it 'creates a deployment' do
- environment = build(:environment)
- service = described_class.new(environment, user, {})
-
- expect(environment.deployments)
- .to receive(:create)
- .with(an_instance_of(Hash))
-
- service.create_deployment
+ describe '#deployment_attributes' do
+ let(:environment) do
+ double(
+ :environment,
+ deployment_platform: double(:platform, cluster_id: 1),
+ project_id: 2,
+ id: 3
+ )
end
- end
- describe '#deployment_attributes' do
it 'only includes attributes that we want to persist' do
service = described_class.new(
environment,
@@ -72,8 +59,7 @@ describe Deployments::CreateService do
tag: true,
sha: '123',
foo: 'bar',
- on_stop: 'stop',
- status: 'running'
+ on_stop: 'stop'
)
expect(service.deployment_attributes).to eq(
@@ -84,8 +70,7 @@ describe Deployments::CreateService do
tag: true,
sha: '123',
user: user,
- on_stop: 'stop',
- status: 'running'
+ on_stop: 'stop'
)
end
end
diff --git a/spec/services/deployments/update_service_spec.rb b/spec/services/deployments/update_service_spec.rb
index 8a918d28ffd..471e90de467 100644
--- a/spec/services/deployments/update_service_spec.rb
+++ b/spec/services/deployments/update_service_spec.rb
@@ -34,9 +34,9 @@ describe Deployments::UpdateService do
expect(deploy).to be_canceled
end
- it 'returns false when the status is not supported' do
- expect(described_class.new(deploy, status: 'kittens').execute)
- .to be_falsey
+ it 'raises ArgumentError if the status is invalid' do
+ expect { described_class.new(deploy, status: 'kittens').execute }
+ .to raise_error(ArgumentError)
end
it 'links merge requests when changing the status to success', :sidekiq_inline do