summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@gitlab.com>2017-03-31 15:47:34 +0200
committerBob Van Landuyt <bob@gitlab.com>2017-04-07 17:24:11 +0200
commita6d313001a9df7f44402b1a0fca8bbd631b9fd87 (patch)
tree7be660e40f24e9c4826393fcf6912e9efbc0550d
parent47abf00b24efb0f6263ea37eddf2d6587950c5ee (diff)
downloadgitlab-ce-a6d313001a9df7f44402b1a0fca8bbd631b9fd87.tar.gz
Wrap updating of cache after pipeline transition in class method
-rw-r--r--app/models/ci/pipeline.rb2
-rw-r--r--lib/gitlab/cache/ci/project_build_status.rb4
-rw-r--r--spec/lib/gitlab/cache/ci/project_build_status_spec.rb14
-rw-r--r--spec/models/ci/pipeline_spec.rb8
4 files changed, 21 insertions, 7 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index b1cabbcd53e..1506a6bf6ab 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -393,7 +393,7 @@ module Ci
end
def refresh_project_build_status_cache
- Gitlab::Cache::Ci::ProjectBuildStatus.new(project, sha: sha, status: status).store_in_cache_if_needed
+ Gitlab::Cache::Ci::ProjectBuildStatus.update_for_pipeline(self)
end
private
diff --git a/lib/gitlab/cache/ci/project_build_status.rb b/lib/gitlab/cache/ci/project_build_status.rb
index d3a0218e6b4..3982caa4a47 100644
--- a/lib/gitlab/cache/ci/project_build_status.rb
+++ b/lib/gitlab/cache/ci/project_build_status.rb
@@ -15,6 +15,10 @@ module Gitlab
end
end
+ def self.update_for_pipeline(pipeline)
+ new(pipeline.project, sha: pipeline.sha, status: pipeline.status).store_in_cache_if_needed
+ end
+
def initialize(project, sha: nil, status: nil)
@project = project
@sha = sha
diff --git a/spec/lib/gitlab/cache/ci/project_build_status_spec.rb b/spec/lib/gitlab/cache/ci/project_build_status_spec.rb
index b7504788255..7b9e959b087 100644
--- a/spec/lib/gitlab/cache/ci/project_build_status_spec.rb
+++ b/spec/lib/gitlab/cache/ci/project_build_status_spec.rb
@@ -12,6 +12,20 @@ describe Gitlab::Cache::Ci::ProjectBuildStatus do
end
end
+ describe '.update_for_pipeline' do
+ it 'refreshes the cache if nescessary' do
+ pipeline = build_stubbed(:ci_pipeline, sha: '123456', status: 'success')
+ fake_status = double
+ expect(described_class).to receive(:new).
+ with(pipeline.project, sha: '123456', status: 'success').
+ and_return(fake_status)
+
+ expect(fake_status).to receive(:store_in_cache_if_needed)
+
+ described_class.update_for_pipeline(pipeline)
+ end
+ end
+
describe '#has_status?' do
it "is false when the status wasn't loaded yet" do
expect(pipeline_status.has_status?).to be_falsy
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index 5caba6ae703..504442392ea 100644
--- a/spec/models/ci/pipeline_spec.rb
+++ b/spec/models/ci/pipeline_spec.rb
@@ -1083,12 +1083,8 @@ describe Ci::Pipeline, models: true do
let(:pipeline) { create(:ci_pipeline, sha: '123456') }
it 'updates the cached status' do
- fake_status = double
- expect(Gitlab::Cache::Ci::ProjectBuildStatus).to receive(:new).
- with(pipeline.project, sha: '123456', status: 'manual').
- and_return(fake_status)
-
- expect(fake_status).to receive(:store_in_cache_if_needed)
+ expect(Gitlab::Cache::Ci::ProjectBuildStatus).to receive(:update_for_pipeline).
+ with(pipeline)
pipeline.block
end