2014-02-03 21:35:48 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe SubmoduleHelper do
|
2015-04-10 01:07:32 -04:00
|
|
|
include RepoHelpers
|
|
|
|
|
2014-02-03 21:35:48 -05:00
|
|
|
describe 'submodule links' do
|
2014-02-10 06:02:26 -05:00
|
|
|
let(:submodule_item) { double(id: 'hash', path: 'rack') }
|
2014-02-03 21:35:48 -05:00
|
|
|
let(:config) { Gitlab.config.gitlab }
|
2014-02-10 06:02:26 -05:00
|
|
|
let(:repo) { double() }
|
|
|
|
|
|
|
|
before do
|
|
|
|
self.instance_variable_set(:@repository, repo)
|
|
|
|
end
|
2014-02-03 21:35:48 -05:00
|
|
|
|
|
|
|
context 'submodule on self' do
|
|
|
|
before do
|
2015-05-21 17:49:06 -04:00
|
|
|
allow(Gitlab.config.gitlab).to receive(:protocol).and_return('http') # set this just to be sure
|
2014-02-03 21:35:48 -05:00
|
|
|
end
|
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'detects ssh on standard port' do
|
2015-05-21 17:49:06 -04:00
|
|
|
allow(Gitlab.config.gitlab_shell).to receive(:ssh_port).and_return(22) # set this just to be sure
|
|
|
|
allow(Gitlab.config.gitlab_shell).to receive(:ssh_path_prefix).and_return(Settings.send(:build_gitlab_shell_ssh_path_prefix))
|
2014-02-10 06:02:26 -05:00
|
|
|
stub_url([ config.user, '@', config.host, ':gitlab-org/gitlab-ce.git' ].join(''))
|
2015-01-24 13:02:58 -05:00
|
|
|
expect(submodule_links(submodule_item)).to eq([ namespace_project_path('gitlab-org', 'gitlab-ce'), namespace_project_tree_path('gitlab-org', 'gitlab-ce', 'hash') ])
|
2014-02-03 21:35:48 -05:00
|
|
|
end
|
2014-02-10 06:02:26 -05:00
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'detects ssh on non-standard port' do
|
2015-05-21 17:49:06 -04:00
|
|
|
allow(Gitlab.config.gitlab_shell).to receive(:ssh_port).and_return(2222)
|
|
|
|
allow(Gitlab.config.gitlab_shell).to receive(:ssh_path_prefix).and_return(Settings.send(:build_gitlab_shell_ssh_path_prefix))
|
2014-02-10 06:02:26 -05:00
|
|
|
stub_url([ 'ssh://', config.user, '@', config.host, ':2222/gitlab-org/gitlab-ce.git' ].join(''))
|
2015-01-24 13:02:58 -05:00
|
|
|
expect(submodule_links(submodule_item)).to eq([ namespace_project_path('gitlab-org', 'gitlab-ce'), namespace_project_tree_path('gitlab-org', 'gitlab-ce', 'hash') ])
|
2014-02-03 21:35:48 -05:00
|
|
|
end
|
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'detects http on standard port' do
|
2015-05-21 17:49:06 -04:00
|
|
|
allow(Gitlab.config.gitlab).to receive(:port).and_return(80)
|
|
|
|
allow(Gitlab.config.gitlab).to receive(:url).and_return(Settings.send(:build_gitlab_url))
|
2014-02-10 06:02:26 -05:00
|
|
|
stub_url([ 'http://', config.host, '/gitlab-org/gitlab-ce.git' ].join(''))
|
2015-01-24 13:02:58 -05:00
|
|
|
expect(submodule_links(submodule_item)).to eq([ namespace_project_path('gitlab-org', 'gitlab-ce'), namespace_project_tree_path('gitlab-org', 'gitlab-ce', 'hash') ])
|
2014-02-03 21:35:48 -05:00
|
|
|
end
|
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'detects http on non-standard port' do
|
2015-05-21 17:49:06 -04:00
|
|
|
allow(Gitlab.config.gitlab).to receive(:port).and_return(3000)
|
|
|
|
allow(Gitlab.config.gitlab).to receive(:url).and_return(Settings.send(:build_gitlab_url))
|
2014-02-10 06:02:26 -05:00
|
|
|
stub_url([ 'http://', config.host, ':3000/gitlab-org/gitlab-ce.git' ].join(''))
|
2015-01-24 13:02:58 -05:00
|
|
|
expect(submodule_links(submodule_item)).to eq([ namespace_project_path('gitlab-org', 'gitlab-ce'), namespace_project_tree_path('gitlab-org', 'gitlab-ce', 'hash') ])
|
2014-02-03 21:35:48 -05:00
|
|
|
end
|
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'works with relative_url_root' do
|
2015-05-21 17:49:06 -04:00
|
|
|
allow(Gitlab.config.gitlab).to receive(:port).and_return(80) # set this just to be sure
|
|
|
|
allow(Gitlab.config.gitlab).to receive(:relative_url_root).and_return('/gitlab/root')
|
|
|
|
allow(Gitlab.config.gitlab).to receive(:url).and_return(Settings.send(:build_gitlab_url))
|
2014-02-10 06:02:26 -05:00
|
|
|
stub_url([ 'http://', config.host, '/gitlab/root/gitlab-org/gitlab-ce.git' ].join(''))
|
2015-01-24 13:02:58 -05:00
|
|
|
expect(submodule_links(submodule_item)).to eq([ namespace_project_path('gitlab-org', 'gitlab-ce'), namespace_project_tree_path('gitlab-org', 'gitlab-ce', 'hash') ])
|
2014-02-03 21:35:48 -05:00
|
|
|
end
|
|
|
|
end
|
2014-02-10 06:02:26 -05:00
|
|
|
|
2014-02-03 21:35:48 -05:00
|
|
|
context 'submodule on github.com' do
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'detects ssh' do
|
2014-02-10 06:02:26 -05:00
|
|
|
stub_url('git@github.com:gitlab-org/gitlab-ce.git')
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(submodule_links(submodule_item)).to eq([ 'https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash' ])
|
2014-02-03 21:35:48 -05:00
|
|
|
end
|
2014-02-10 06:02:26 -05:00
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'detects http' do
|
2014-02-10 06:02:26 -05:00
|
|
|
stub_url('http://github.com/gitlab-org/gitlab-ce.git')
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(submodule_links(submodule_item)).to eq([ 'https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash' ])
|
2014-02-03 21:35:48 -05:00
|
|
|
end
|
2014-02-10 06:02:26 -05:00
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'detects https' do
|
2014-02-10 06:02:26 -05:00
|
|
|
stub_url('https://github.com/gitlab-org/gitlab-ce.git')
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(submodule_links(submodule_item)).to eq([ 'https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash' ])
|
2014-02-03 21:35:48 -05:00
|
|
|
end
|
2014-02-10 06:02:26 -05:00
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'returns original with non-standard url' do
|
2014-02-10 06:02:26 -05:00
|
|
|
stub_url('http://github.com/gitlab-org/gitlab-ce')
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(submodule_links(submodule_item)).to eq([ repo.submodule_url_for, nil ])
|
2014-02-03 21:35:48 -05:00
|
|
|
|
2014-02-10 06:02:26 -05:00
|
|
|
stub_url('http://github.com/another/gitlab-org/gitlab-ce.git')
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(submodule_links(submodule_item)).to eq([ repo.submodule_url_for, nil ])
|
2014-02-03 21:35:48 -05:00
|
|
|
end
|
|
|
|
end
|
2014-02-10 06:02:26 -05:00
|
|
|
|
2014-02-03 21:35:48 -05:00
|
|
|
context 'submodule on gitlab.com' do
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'detects ssh' do
|
2014-02-10 06:02:26 -05:00
|
|
|
stub_url('git@gitlab.com:gitlab-org/gitlab-ce.git')
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(submodule_links(submodule_item)).to eq([ 'https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash' ])
|
2014-02-03 21:35:48 -05:00
|
|
|
end
|
2014-02-10 06:02:26 -05:00
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'detects http' do
|
2014-02-10 06:02:26 -05:00
|
|
|
stub_url('http://gitlab.com/gitlab-org/gitlab-ce.git')
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(submodule_links(submodule_item)).to eq([ 'https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash' ])
|
2014-02-03 21:35:48 -05:00
|
|
|
end
|
2014-02-10 06:02:26 -05:00
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'detects https' do
|
2014-02-10 06:02:26 -05:00
|
|
|
stub_url('https://gitlab.com/gitlab-org/gitlab-ce.git')
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(submodule_links(submodule_item)).to eq([ 'https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash' ])
|
2014-02-03 21:35:48 -05:00
|
|
|
end
|
2014-02-10 06:02:26 -05:00
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'returns original with non-standard url' do
|
2014-02-10 06:02:26 -05:00
|
|
|
stub_url('http://gitlab.com/gitlab-org/gitlab-ce')
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(submodule_links(submodule_item)).to eq([ repo.submodule_url_for, nil ])
|
2014-02-03 21:35:48 -05:00
|
|
|
|
2014-02-10 06:02:26 -05:00
|
|
|
stub_url('http://gitlab.com/another/gitlab-org/gitlab-ce.git')
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(submodule_links(submodule_item)).to eq([ repo.submodule_url_for, nil ])
|
2014-02-03 21:35:48 -05:00
|
|
|
end
|
|
|
|
end
|
2014-02-10 06:02:26 -05:00
|
|
|
|
2014-02-03 21:35:48 -05:00
|
|
|
context 'submodule on unsupported' do
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'returns original' do
|
2014-02-10 06:02:26 -05:00
|
|
|
stub_url('http://mygitserver.com/gitlab-org/gitlab-ce')
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(submodule_links(submodule_item)).to eq([ repo.submodule_url_for, nil ])
|
2014-02-03 21:35:48 -05:00
|
|
|
|
2014-02-10 06:02:26 -05:00
|
|
|
stub_url('http://mygitserver.com/gitlab-org/gitlab-ce.git')
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(submodule_links(submodule_item)).to eq([ repo.submodule_url_for, nil ])
|
2014-02-03 21:35:48 -05:00
|
|
|
end
|
|
|
|
end
|
2015-04-10 01:07:32 -04:00
|
|
|
|
|
|
|
context 'submodules with relative links' do
|
2015-06-22 10:33:32 -04:00
|
|
|
let(:group) { create(:group, name: "Master Project", path: "master-project") }
|
2017-01-25 17:10:32 -05:00
|
|
|
let(:project) { create(:empty_project, group: group) }
|
2015-04-23 10:42:28 -04:00
|
|
|
let(:commit_id) { sample_commit[:id] }
|
2015-04-10 01:07:32 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
self.instance_variable_set(:@project, project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'one level down' do
|
|
|
|
result = relative_self_links('../test.git', commit_id)
|
|
|
|
expect(result).to eq(["/#{group.path}/test", "/#{group.path}/test/tree/#{commit_id}"])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'two levels down' do
|
|
|
|
result = relative_self_links('../../test.git', commit_id)
|
|
|
|
expect(result).to eq(["/#{group.path}/test", "/#{group.path}/test/tree/#{commit_id}"])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'one level down with namespace and repo' do
|
|
|
|
result = relative_self_links('../foobar/test.git', commit_id)
|
|
|
|
expect(result).to eq(["/foobar/test", "/foobar/test/tree/#{commit_id}"])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'two levels down with namespace and repo' do
|
|
|
|
result = relative_self_links('../foobar/baz/test.git', commit_id)
|
|
|
|
expect(result).to eq(["/baz/test", "/baz/test/tree/#{commit_id}"])
|
|
|
|
end
|
2015-04-23 10:42:28 -04:00
|
|
|
|
|
|
|
context 'personal project' do
|
|
|
|
let(:user) { create(:user) }
|
2017-01-25 17:10:32 -05:00
|
|
|
let(:project) { create(:empty_project, namespace: user.namespace) }
|
2015-04-23 10:42:28 -04:00
|
|
|
|
|
|
|
it 'one level down with personal project' do
|
|
|
|
result = relative_self_links('../test.git', commit_id)
|
|
|
|
expect(result).to eq(["/#{user.username}/test", "/#{user.username}/test/tree/#{commit_id}"])
|
|
|
|
end
|
|
|
|
end
|
2015-04-10 01:07:32 -04:00
|
|
|
end
|
2014-02-03 21:35:48 -05:00
|
|
|
end
|
2014-02-10 06:02:26 -05:00
|
|
|
|
|
|
|
def stub_url(url)
|
2015-05-21 17:49:06 -04:00
|
|
|
allow(repo).to receive(:submodule_url_for).and_return(url)
|
2014-02-10 06:02:26 -05:00
|
|
|
end
|
2014-02-03 21:35:48 -05:00
|
|
|
end
|