Commit 6fbfa060 authored by Stan Hu's avatar Stan Hu

Merge branch '11124-update-deployment-service-fails-if-project-is-nil' into 'master'

Always return the deployment in the UpdateDeploymentService#execute method

Closes gitlab-ee#11124

See merge request gitlab-org/gitlab-ce!27322
parents c59f68e8 0723df52
...@@ -27,6 +27,8 @@ class UpdateDeploymentService ...@@ -27,6 +27,8 @@ class UpdateDeploymentService
deployment.tap(&:update_merge_request_metrics!) deployment.tap(&:update_merge_request_metrics!)
end end
deployment
end end
private private
......
---
title: Always return the deployment in the UpdateDeploymentService#execute method
merge_request: 27322
author:
type: fixed
...@@ -4,6 +4,7 @@ require 'spec_helper' ...@@ -4,6 +4,7 @@ require 'spec_helper'
describe UpdateDeploymentService do describe UpdateDeploymentService do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project, :repository) }
let(:options) { { name: 'production' } } let(:options) { { name: 'production' } }
let(:job) do let(:job) do
...@@ -15,24 +16,22 @@ describe UpdateDeploymentService do ...@@ -15,24 +16,22 @@ describe UpdateDeploymentService do
project: project) project: project)
end end
let(:project) { create(:project, :repository) }
let(:environment) { deployment.environment }
let(:deployment) { job.deployment } let(:deployment) { job.deployment }
let(:service) { described_class.new(deployment) } let(:environment) { deployment.environment }
subject(:service) { described_class.new(deployment) }
before do before do
job.success! # Create/Succeed deployment job.success! # Create/Succeed deployment
end end
describe '#execute' do describe '#execute' do
subject { service.execute }
let(:store) { Gitlab::EtagCaching::Store.new } let(:store) { Gitlab::EtagCaching::Store.new }
it 'invalidates the environment etag cache' do it 'invalidates the environment etag cache' do
old_value = store.get(environment.etag_cache_key) old_value = store.get(environment.etag_cache_key)
subject service.execute
expect(store.get(environment.etag_cache_key)).not_to eq(old_value) expect(store.get(environment.etag_cache_key)).not_to eq(old_value)
end end
...@@ -42,14 +41,30 @@ describe UpdateDeploymentService do ...@@ -42,14 +41,30 @@ describe UpdateDeploymentService do
.to receive(:create_ref) .to receive(:create_ref)
.with(deployment.ref, deployment.send(:ref_path)) .with(deployment.ref, deployment.send(:ref_path))
subject service.execute
end end
it 'updates merge request metrics' do it 'updates merge request metrics' do
expect_any_instance_of(Deployment) expect_any_instance_of(Deployment)
.to receive(:update_merge_request_metrics!) .to receive(:update_merge_request_metrics!)
subject service.execute
end
it 'returns the deployment' do
expect(subject.execute).to eq(deployment)
end
it 'returns the deployment when could not save the environment' do
allow(environment).to receive(:save).and_return(false)
expect(subject.execute).to eq(deployment)
end
it 'returns the deployment when environment is stopped' do
allow(environment).to receive(:stopped?).and_return(true)
expect(subject.execute).to eq(deployment)
end end
context 'when start action is defined' do context 'when start action is defined' do
...@@ -61,7 +76,7 @@ describe UpdateDeploymentService do ...@@ -61,7 +76,7 @@ describe UpdateDeploymentService do
end end
it 'makes environment available' do it 'makes environment available' do
subject service.execute
expect(environment.reload).to be_available expect(environment.reload).to be_available
end end
...@@ -80,11 +95,11 @@ describe UpdateDeploymentService do ...@@ -80,11 +95,11 @@ describe UpdateDeploymentService do
end end
it 'does not create a new environment' do it 'does not create a new environment' do
expect { subject }.not_to change { Environment.count } expect { subject.execute }.not_to change { Environment.count }
end end
it 'updates external url' do it 'updates external url' do
subject subject.execute
expect(subject.environment.name).to eq('review-apps/master') expect(subject.environment.name).to eq('review-apps/master')
expect(subject.environment.external_url).to eq('http://master.review-apps.gitlab.com') expect(subject.environment.external_url).to eq('http://master.review-apps.gitlab.com')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment