Commit 6467ddd2 authored by Kerri Miller's avatar Kerri Miller

Merge branch 'fix-commit-cache-key' into 'master'

Fix pipeline status for commit caching

See merge request gitlab-org/gitlab!61920
parents 179d5249 076a36a4
......@@ -161,7 +161,7 @@ module CommitsHelper
ref,
{
merge_request: merge_request,
pipeline_status: hashed_pipeline_status(commit, ref),
pipeline_status: commit.status_for(ref),
xhr: request.xhr?,
controller: controller.controller_path,
path: @path # referred to in #link_to_browse_code
......@@ -242,14 +242,4 @@ module CommitsHelper
project_commit_path(project, commit)
end
end
private
def hashed_pipeline_status(commit, ref)
status = commit.status_for(ref)
return if status.nil?
Digest::SHA1.hexdigest(status.to_s)
end
end
......@@ -11,6 +11,8 @@ module Gitlab
attr_reader :subject, :user
delegate :cache_key, to: :subject
def initialize(subject, user)
@subject = subject
@user = user
......
......@@ -291,10 +291,11 @@ RSpec.describe CommitsHelper do
end
describe "#commit_partial_cache_key" do
subject { helper.commit_partial_cache_key(commit, ref: ref, merge_request: merge_request, request: request) }
subject(:cache_key) { helper.commit_partial_cache_key(commit, ref: ref, merge_request: merge_request, request: request) }
let(:commit) { create(:commit).present(current_user: user) }
let(:commit_status) { create(:commit_status) }
let(:commit_status) { Gitlab::Ci::Status::Running.new(pipeline, user) }
let(:pipeline) { create(:ci_pipeline, :running) }
let(:user) { create(:user) }
let(:ref) { "master" }
let(:merge_request) { nil }
......@@ -315,12 +316,19 @@ RSpec.describe CommitsHelper do
is_expected.to include(
{
merge_request: merge_request,
pipeline_status: Digest::SHA1.hexdigest(commit_status.to_s),
pipeline_status: commit_status,
xhr: true,
controller: "commits",
path: current_path
}
)
end
describe "final cache key output" do
subject { ActiveSupport::Cache.expand_cache_key(cache_key) }
it { is_expected.to include(commit.cache_key) }
it { is_expected.to include(pipeline.cache_key) }
end
end
end
# frozen_string_literal: true
require "spec_helper"
RSpec.describe Gitlab::Ci::Status::Core do
let(:subj) { double("subject", cache_key: "foo") }
subject(:status) do
described_class.new(subj, double("user"))
end
describe "#cache_key" do
it "uses the subject's cache key" do
expect(status.cache_key).to eq(subj.cache_key)
end
end
end
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