Commit 1281ac55 authored by Igor's avatar Igor Committed by Kamil Trzciński

Fix caching of submodule links for shas with dashes

parent f1e701e0
...@@ -6,6 +6,7 @@ module Gitlab ...@@ -6,6 +6,7 @@ module Gitlab
def initialize(repository) def initialize(repository)
@repository = repository @repository = repository
@cache_store = {}
end end
def for(submodule, sha) def for(submodule, sha)
...@@ -18,8 +19,9 @@ module Gitlab ...@@ -18,8 +19,9 @@ module Gitlab
attr_reader :repository attr_reader :repository
def submodule_urls_for(sha) def submodule_urls_for(sha)
strong_memoize(:"submodule_urls_for_#{sha}") do @cache_store.fetch(sha) do
repository.submodule_urls_for(sha) submodule_urls = repository.submodule_urls_for(sha)
@cache_store[sha] = submodule_urls
end end
end end
......
...@@ -8,7 +8,9 @@ describe Gitlab::SubmoduleLinks do ...@@ -8,7 +8,9 @@ describe Gitlab::SubmoduleLinks do
let(:links) { described_class.new(repo) } let(:links) { described_class.new(repo) }
describe '#for' do describe '#for' do
subject { links.for(submodule_item, 'ref') } let(:ref) { 'ref' }
subject { links.for(submodule_item, ref) }
context 'when there is no .gitmodules file' do context 'when there is no .gitmodules file' do
before do before do
...@@ -35,11 +37,23 @@ describe Gitlab::SubmoduleLinks do ...@@ -35,11 +37,23 @@ describe Gitlab::SubmoduleLinks do
stub_urls({ 'gitlab-foss' => 'git@gitlab.com:gitlab-org/gitlab-foss.git' }) stub_urls({ 'gitlab-foss' => 'git@gitlab.com:gitlab-org/gitlab-foss.git' })
end end
it 'returns links and caches the by ref' do
expect(subject).to eq(['https://gitlab.com/gitlab-org/gitlab-foss', 'https://gitlab.com/gitlab-org/gitlab-foss/tree/hash'])
cache_store = links.instance_variable_get("@cache_store")
expect(cache_store[ref]).to eq({ "gitlab-foss" => "git@gitlab.com:gitlab-org/gitlab-foss.git" })
end
context 'when ref name contains a dash' do
let(:ref) { 'signed-commits' }
it 'returns links' do it 'returns links' do
expect(subject).to eq(['https://gitlab.com/gitlab-org/gitlab-foss', 'https://gitlab.com/gitlab-org/gitlab-foss/tree/hash']) expect(subject).to eq(['https://gitlab.com/gitlab-org/gitlab-foss', 'https://gitlab.com/gitlab-org/gitlab-foss/tree/hash'])
end end
end end
end end
end
def stub_urls(urls) def stub_urls(urls)
allow(repo).to receive(:submodule_urls_for).and_return(urls) allow(repo).to receive(:submodule_urls_for).and_return(urls)
......
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