From f6a11d00a8d938293a6a223c6f227b935ebe7a3c Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 18 Apr 2017 22:20:47 +0200 Subject: [PATCH] Fix duplicated container repository names --- lib/container_registry/path.rb | 10 ++++++-- spec/lib/container_registry/path_spec.rb | 31 +++++++++++++++++++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/lib/container_registry/path.rb b/lib/container_registry/path.rb index 4a585996aa5..61849a40383 100644 --- a/lib/container_registry/path.rb +++ b/lib/container_registry/path.rb @@ -48,7 +48,7 @@ module ContainerRegistry end def root_repository? - @path == repository_project.full_path + @path == project_path end def repository_project @@ -60,7 +60,13 @@ module ContainerRegistry def repository_name return unless has_project? - @path.remove(%r(^#{Regexp.escape(repository_project.full_path)}/?)) + @path.remove(%r(^#{Regexp.escape(project_path)}/?)) + end + + def project_path + return unless has_project? + + repository_project.full_path.downcase end def to_s diff --git a/spec/lib/container_registry/path_spec.rb b/spec/lib/container_registry/path_spec.rb index f3b3a9a715f..0023985e1c2 100644 --- a/spec/lib/container_registry/path_spec.rb +++ b/spec/lib/container_registry/path_spec.rb @@ -189,7 +189,7 @@ describe ContainerRegistry::Path do end context 'when project exists' do - let(:group) { create(:group, path: 'some_group') } + let(:group) { create(:group, path: 'Some_Group') } let(:project) do create(:empty_project, group: group, name: 'some_project') @@ -225,4 +225,33 @@ describe ContainerRegistry::Path do end end end + + describe '#project_path' do + context 'when project does not exist' do + let(:path) { 'some/name' } + + it 'returns nil' do + expect(subject.project_path).to be_nil + end + end + + context 'when project with uppercase characters in path exists' do + let(:path) { 'somegroup/someproject' } + + let(:group) { create(:group, path: 'SomeGroup') } + + let(:project) do + create(:empty_project, group: group, name: 'SomeProject') + end + + before do + allow(path).to receive(:repository_project) + .and_return(project) + end + + it 'returns downcased project path' do + expect(subject.project_path).to eq 'somegroup/someproject' + end + end + end end