diff options
author | Bob Van Landuyt <bob@gitlab.com> | 2017-04-06 15:20:29 +0300 |
---|---|---|
committer | Bob Van Landuyt <bob@gitlab.com> | 2017-04-07 18:24:11 +0300 |
commit | 516a405eb277e088d3b4ae3cb6e64f0bd2d3aff0 (patch) | |
tree | d67a59241e938abaf11e69f3ccb908d84dfef3f6 /spec/lib/gitlab/cache | |
parent | 02072e17ab484d7c99dc485fc3ef8348f8da8bf1 (diff) |
Take the ref of a pipeline into account when caching status
Diffstat (limited to 'spec/lib/gitlab/cache')
-rw-r--r-- | spec/lib/gitlab/cache/ci/project_pipeline_status_spec.rb | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/spec/lib/gitlab/cache/ci/project_pipeline_status_spec.rb b/spec/lib/gitlab/cache/ci/project_pipeline_status_spec.rb index ada9bf136f4..fced253dd01 100644 --- a/spec/lib/gitlab/cache/ci/project_pipeline_status_spec.rb +++ b/spec/lib/gitlab/cache/ci/project_pipeline_status_spec.rb @@ -17,7 +17,7 @@ describe Gitlab::Cache::Ci::ProjectPipelineStatus 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'). + with(pipeline.project, sha: '123456', status: 'success', ref: 'master'). and_return(fake_status) expect(fake_status).to receive(:store_in_cache_if_needed) @@ -55,14 +55,14 @@ describe Gitlab::Cache::Ci::ProjectPipelineStatus do it 'loads the status from the project commit when there is no cache' do allow(pipeline_status).to receive(:has_cache?).and_return(false) - expect(pipeline_status).to receive(:load_from_commit) + expect(pipeline_status).to receive(:load_from_project) pipeline_status.load_status end it 'stores the status in the cache when it loading it from the project' do allow(pipeline_status).to receive(:has_cache?).and_return(false) - allow(pipeline_status).to receive(:load_from_commit) + allow(pipeline_status).to receive(:load_from_project) expect(pipeline_status).to receive(:store_in_cache) @@ -84,14 +84,15 @@ describe Gitlab::Cache::Ci::ProjectPipelineStatus do end end - describe "#load_from_commit" do + describe "#load_from_project" do let!(:pipeline) { create(:ci_pipeline, :success, project: project, sha: project.commit.sha) } it 'reads the status from the pipeline for the commit' do - pipeline_status.load_from_commit + pipeline_status.load_from_project expect(pipeline_status.status).to eq('success') expect(pipeline_status.sha).to eq(project.commit.sha) + expect(pipeline_status.ref).to eq(project.default_branch) end it "doesn't fail for an empty project" do @@ -122,10 +123,11 @@ describe Gitlab::Cache::Ci::ProjectPipelineStatus do build_status = described_class.load_for_project(project) build_status.store_in_cache_if_needed - sha, status = Gitlab::Redis.with { |redis| redis.hmget("projects/#{project.id}/build_status", :sha, :status) } + sha, status, ref = Gitlab::Redis.with { |redis| redis.hmget("projects/#{project.id}/build_status", :sha, :status, :ref) } expect(sha).not_to be_nil expect(status).not_to be_nil + expect(ref).not_to be_nil end it "doesn't store the status in redis when the sha is not the head of the project" do @@ -140,14 +142,15 @@ describe Gitlab::Cache::Ci::ProjectPipelineStatus do it "deletes the cache if the repository doesn't have a head commit" do empty_project = create(:empty_project) - Gitlab::Redis.with { |redis| redis.mapped_hmset("projects/#{empty_project.id}/build_status", { sha: "sha", status: "pending" }) } + Gitlab::Redis.with { |redis| redis.mapped_hmset("projects/#{empty_project.id}/build_status", { sha: "sha", status: "pending", ref: 'master' }) } other_status = described_class.new(empty_project, sha: "123456", status: "failed") other_status.store_in_cache_if_needed - sha, status = Gitlab::Redis.with { |redis| redis.hmget("projects/#{empty_project.id}/build_status", :sha, :status) } + sha, status, ref = Gitlab::Redis.with { |redis| redis.hmget("projects/#{empty_project.id}/build_status", :sha, :status, :ref) } expect(sha).to be_nil expect(status).to be_nil + expect(ref).to be_nil end end |