Wrap updating of cache after pipeline transition in class method

This commit is contained in:
Bob Van Landuyt 2017-03-31 15:47:34 +02:00
parent 47abf00b24
commit a6d313001a
4 changed files with 21 additions and 7 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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