diff options
Diffstat (limited to 'spec/helpers')
-rw-r--r-- | spec/helpers/submodule_helper_spec.rb | 75 |
1 files changed, 55 insertions, 20 deletions
diff --git a/spec/helpers/submodule_helper_spec.rb b/spec/helpers/submodule_helper_spec.rb index a64f8a11ef2..8662cadc7a0 100644 --- a/spec/helpers/submodule_helper_spec.rb +++ b/spec/helpers/submodule_helper_spec.rb @@ -162,42 +162,77 @@ describe SubmoduleHelper do end context 'submodules with relative links' do - let(:group) { create(:group, name: "Master Project", path: "master-project") } + let(:group) { create(:group, name: "top group", path: "top-group") } let(:project) { create(:project, group: group) } - let(:commit_id) { sample_commit[:id] } + let(:repo) { double(:repo, project: project) } + + def expect_relative_link_to_resolve_to(relative_path, expected_path) + allow(repo).to receive(:submodule_url_for).and_return(relative_path) + + result = submodule_links(submodule_item) + + expect(result).to eq([expected_path, "#{expected_path}/tree/#{submodule_item.id}"]) + end - it 'one level down' do - result = relative_self_links('../test.git', commit_id, project) - expect(result).to eq(["/#{group.path}/test", "/#{group.path}/test/tree/#{commit_id}"]) + it 'handles project under same group' do + expect_relative_link_to_resolve_to('../test.git', "/#{group.path}/test") end - it 'with trailing whitespace' do - result = relative_self_links('../test.git ', commit_id, project) - expect(result).to eq(["/#{group.path}/test", "/#{group.path}/test/tree/#{commit_id}"]) + it 'handles trailing whitespace' do + expect_relative_link_to_resolve_to('../test.git ', "/#{group.path}/test") end - it 'two levels down' do - result = relative_self_links('../../test.git', commit_id, project) - expect(result).to eq(["/#{group.path}/test", "/#{group.path}/test/tree/#{commit_id}"]) + it 'handles project under another top group' do + expect_relative_link_to_resolve_to('../../baz/test.git ', "/baz/test") + end + + context 'repo path resolves to be located at root (namespace absent)' do + it 'returns nil' do + allow(repo).to receive(:submodule_url_for).and_return('../../test.git') + + result = submodule_links(submodule_item) + + expect(result).to eq([nil, nil]) + end end - it 'one level down with namespace and repo' do - result = relative_self_links('../foobar/test.git', commit_id, project) - expect(result).to eq(["/foobar/test", "/foobar/test/tree/#{commit_id}"]) + context 'repo path resolves to be located underneath current project path' do + it 'returns nil because it is not possible to have repo nested under another repo' do + allow(repo).to receive(:submodule_url_for).and_return('./test.git') + + result = submodule_links(submodule_item) + + expect(result).to eq([nil, nil]) + end end - it 'two levels down with namespace and repo' do - result = relative_self_links('../foobar/baz/test.git', commit_id, project) - expect(result).to eq(["/baz/test", "/baz/test/tree/#{commit_id}"]) + context 'subgroup' do + let(:sub_group) { create(:group, parent: group, name: "sub group", path: "sub-group") } + let(:sub_project) { create(:project, group: sub_group) } + + context 'project in sub group' do + let(:project) { sub_project } + + it "handles referencing ancestor group's project" do + expect_relative_link_to_resolve_to('../../../top-group/test.git', "/#{group.path}/test") + end + end + + it "handles referencing descendent group's project" do + expect_relative_link_to_resolve_to('../sub-group/test.git', "/top-group/sub-group/test") + end + + it "handles referencing another top group's project" do + expect_relative_link_to_resolve_to('../../frontend/css/test.git', "/frontend/css/test") + end end context 'personal project' do let(:user) { create(:user) } let(:project) { create(:project, namespace: user.namespace) } - it 'one level down with personal project' do - result = relative_self_links('../test.git', commit_id, project) - expect(result).to eq(["/#{user.username}/test", "/#{user.username}/test/tree/#{commit_id}"]) + it 'handles referencing another personal project' do + expect_relative_link_to_resolve_to('../test.git', "/#{user.username}/test") end end end |