Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2018-10-25 14:09:10 +0300
committerShinya Maeda <shinya@gitlab.com>2018-10-30 07:42:14 +0300
commitb39259fa29bed2fa12778fed4a1a6a1a1987b391 (patch)
tree4285c6b0daa090b8cb93df6b63ffa74d8e9cd15f
parent1f9dea8b4ae8c3ca5e9a0b50cea0e4cab6e2ad9d (diff)
Rename to update deployment service
-rw-r--r--app/services/update_deployment_service.rb (renamed from app/services/update_deployment_metrics_service.rb)5
-rw-r--r--app/workers/ci/deployment_success_worker.rb4
-rw-r--r--spec/services/update_deployment_service_spec.rb (renamed from spec/services/update_deployment_metrics_service_spec.rb)36
-rw-r--r--spec/workers/ci/deployment_success_worker_spec.rb23
4 files changed, 51 insertions, 17 deletions
diff --git a/app/services/update_deployment_metrics_service.rb b/app/services/update_deployment_service.rb
index df9053b7ff6..aa7fcca1e2a 100644
--- a/app/services/update_deployment_metrics_service.rb
+++ b/app/services/update_deployment_service.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-class UpdateDeploymentMetricsService
+class UpdateDeploymentService
attr_reader :deployment
attr_reader :deployable
@@ -13,6 +13,9 @@ class UpdateDeploymentMetricsService
end
def execute
+ deployment.create_ref
+ deployment.invalidate_cache
+
ActiveRecord::Base.transaction do
environment.external_url = expanded_environment_url if
expanded_environment_url
diff --git a/app/workers/ci/deployment_success_worker.rb b/app/workers/ci/deployment_success_worker.rb
index 18ce9242ea9..d54864f6460 100644
--- a/app/workers/ci/deployment_success_worker.rb
+++ b/app/workers/ci/deployment_success_worker.rb
@@ -9,9 +9,7 @@ module Ci
def perform(deployment_id)
Deployment.find_by_id(deployment_id).try do |deployment|
- deployment.create_ref
- deployment.invalidate_cache
- UpdateDeploymentMetricsService.new(deployment).execute
+ UpdateDeploymentService.new(deployment).execute
end
end
end
diff --git a/spec/services/update_deployment_metrics_service_spec.rb b/spec/services/update_deployment_service_spec.rb
index e4a853b5251..49b19b53ebe 100644
--- a/spec/services/update_deployment_metrics_service_spec.rb
+++ b/spec/services/update_deployment_service_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe UpdateDeploymentMetricsService do
+describe UpdateDeploymentService do
let(:user) { create(:user) }
let(:options) { nil }
@@ -9,10 +9,11 @@ describe UpdateDeploymentMetricsService do
ref: 'master',
tag: false,
environment: 'production',
- options: { environment: options })
+ options: { environment: options },
+ project: project)
end
- let(:project) { job.project }
+ let(:project) { create(:project, :repository) }
let(:environment) { job.persisted_environment }
@@ -20,7 +21,6 @@ describe UpdateDeploymentMetricsService do
let(:service) { described_class.new(deployment) }
before do
- allow_any_instance_of(Deployment).to receive(:create_ref)
allow(Ci::DeploymentSuccessWorker).to receive(:perform_async)
job.success!
@@ -29,6 +29,31 @@ describe UpdateDeploymentMetricsService do
describe '#execute' do
subject { service.execute }
+ let(:store) { Gitlab::EtagCaching::Store.new }
+
+ it 'invalidates the environment etag cache' do
+ old_value = store.get(environment.etag_cache_key)
+
+ subject
+
+ expect(store.get(environment.etag_cache_key)).not_to eq(old_value)
+ end
+
+ it 'creates ref' do
+ expect_any_instance_of(Repository)
+ .to receive(:create_ref)
+ .with(deployment.ref, deployment.send(:ref_path))
+
+ subject
+ end
+
+ it 'updates merge request metrics' do
+ expect_any_instance_of(Deployment)
+ .to receive(:update_merge_request_metrics!)
+
+ subject
+ end
+
context 'when start action is defined' do
let(:options) { { action: 'start' } }
@@ -152,7 +177,8 @@ describe UpdateDeploymentMetricsService do
ref: 'master',
tag: false,
environment: 'staging',
- options: { environment: options })
+ options: { environment: options },
+ project: project)
end
it "doesn't set the time if the deploy's environment is not 'production'" do
diff --git a/spec/workers/ci/deployment_success_worker_spec.rb b/spec/workers/ci/deployment_success_worker_spec.rb
index 1a0434b41f7..b112adf7bc8 100644
--- a/spec/workers/ci/deployment_success_worker_spec.rb
+++ b/spec/workers/ci/deployment_success_worker_spec.rb
@@ -1,19 +1,26 @@
require 'spec_helper'
describe Ci::DeploymentSuccessWorker do
- subject { described_class.new.perform(deployment.id) }
+ subject { described_class.new.perform(deployment&.id) }
- describe '#execute' do
- let(:environment) { create(:environment) }
- let!(:deployment) { create(:deployment, environment: environment) }
- let(:store) { Gitlab::EtagCaching::Store.new }
+ context 'when deploy record exists' do
+ let(:deployment) { create(:deployment) }
- it 'invalidates the environment etag cache' do
- old_value = store.get(environment.etag_cache_key)
+ it 'executes UpdateDeploymentService' do
+ expect(UpdateDeploymentService)
+ .to receive(:new).with(deployment).and_call_original
subject
+ end
+ end
+
+ context 'when deploy record does not exist' do
+ let(:deployment) { nil }
- expect(store.get(environment.etag_cache_key)).not_to eq(old_value)
+ it 'executes UpdateDeploymentService' do
+ expect(UpdateDeploymentService).not_to receive(:new)
+
+ subject
end
end
end