diff options
author | Jason Hollingsworth <jhworth.developer@gmail.com> | 2014-02-03 20:35:48 -0600 |
---|---|---|
committer | Jason Hollingsworth <jhworth.developer@gmail.com> | 2014-02-05 20:44:14 -0600 |
commit | fcc906e6aa1749046b691bbd60b2020fc970bdfb (patch) | |
tree | 4787f1283151b64ce77776722fa831ab40d496d1 /spec/helpers | |
parent | 883409b941b591a482a4d883a4925d87c00b18a6 (diff) | |
download | gitlab-ce-fcc906e6aa1749046b691bbd60b2020fc970bdfb.tar.gz |
Better submodule links.
Detect if submodule is hosted on this GitLab server, gitlab.com or github.com.
Hash links directly to commit in repo.
Diffstat (limited to 'spec/helpers')
-rw-r--r-- | spec/helpers/submodule_helper_spec.rb | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/spec/helpers/submodule_helper_spec.rb b/spec/helpers/submodule_helper_spec.rb new file mode 100644 index 00000000000..507812e5223 --- /dev/null +++ b/spec/helpers/submodule_helper_spec.rb @@ -0,0 +1,109 @@ +require 'spec_helper' + +describe SubmoduleHelper do + describe 'submodule links' do + let(:submodule_item) { double(submodule_url: '', id: 'hash') } + let(:config) { Gitlab.config.gitlab } + + context 'submodule on self' do + before do + Gitlab.config.gitlab.stub(protocol: 'http') # set this just to be sure + end + + it 'should detect ssh on standard port' do + Gitlab.config.gitlab.stub(ssh_port: 22) # set this just to be sure + submodule_item.stub(submodule_url: [ config.user, '@', config.host, ':gitlab-org/gitlab-ce.git' ].join('')) + submodule_links(submodule_item).should == [ project_path('gitlab-org/gitlab-ce'), project_tree_path('gitlab-org/gitlab-ce', 'hash') ] + end + + it 'should detect ssh on non-standard port' do + Gitlab.config.gitlab_shell.stub(ssh_port: 2222) + Gitlab.config.gitlab_shell.stub(ssh_path_prefix: Settings.send(:build_gitlab_shell_ssh_path_prefix)) + submodule_item.stub(submodule_url: [ 'ssh://', config.user, '@', config.host, ':2222/gitlab-org/gitlab-ce.git' ].join('')) + submodule_links(submodule_item).should == [ project_path('gitlab-org/gitlab-ce'), project_tree_path('gitlab-org/gitlab-ce', 'hash') ] + end + + it 'should detect http on standard port' do + Gitlab.config.gitlab.stub(port: 80) + Gitlab.config.gitlab.stub(url: Settings.send(:build_gitlab_url)) + submodule_item.stub(submodule_url: [ 'http://', config.host, '/gitlab-org/gitlab-ce.git' ].join('')) + submodule_links(submodule_item).should == [ project_path('gitlab-org/gitlab-ce'), project_tree_path('gitlab-org/gitlab-ce', 'hash') ] + end + + it 'should detect http on non-standard port' do + Gitlab.config.gitlab.stub(port: 3000) + Gitlab.config.gitlab.stub(url: Settings.send(:build_gitlab_url)) + submodule_item.stub(submodule_url: [ 'http://', config.host, ':3000/gitlab-org/gitlab-ce.git' ].join('')) + submodule_links(submodule_item).should == [ project_path('gitlab-org/gitlab-ce'), project_tree_path('gitlab-org/gitlab-ce', 'hash') ] + end + + it 'should work with relative_url_root' do + Gitlab.config.gitlab.stub(port: 80) # set this just to be sure + Gitlab.config.gitlab.stub(relative_url_root: '/gitlab/root') + Gitlab.config.gitlab.stub(url: Settings.send(:build_gitlab_url)) + submodule_item.stub(submodule_url: [ 'http://', config.host, '/gitlab/root/gitlab-org/gitlab-ce.git' ].join('')) + submodule_links(submodule_item).should == [ project_path('gitlab-org/gitlab-ce'), project_tree_path('gitlab-org/gitlab-ce', 'hash') ] + end + end + + context 'submodule on github.com' do + it 'should detect ssh' do + submodule_item.stub(submodule_url: 'git@github.com:gitlab-org/gitlab-ce.git') + submodule_links(submodule_item).should == [ 'https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash' ] + end + + it 'should detect http' do + submodule_item.stub(submodule_url: 'http://github.com/gitlab-org/gitlab-ce.git') + submodule_links(submodule_item).should == [ 'https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash' ] + end + + it 'should detect https' do + submodule_item.stub(submodule_url: 'https://github.com/gitlab-org/gitlab-ce.git') + submodule_links(submodule_item).should == [ 'https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash' ] + end + + it 'should return original with non-standard url' do + submodule_item.stub(submodule_url: 'http://github.com/gitlab-org/gitlab-ce') + submodule_links(submodule_item).should == [ submodule_item.submodule_url, nil ] + + submodule_item.stub(submodule_url: 'http://github.com/another/gitlab-org/gitlab-ce.git') + submodule_links(submodule_item).should == [ submodule_item.submodule_url, nil ] + end + end + + context 'submodule on gitlab.com' do + it 'should detect ssh' do + submodule_item.stub(submodule_url: 'git@gitlab.com:gitlab-org/gitlab-ce.git') + submodule_links(submodule_item).should == [ 'https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash' ] + end + + it 'should detect http' do + submodule_item.stub(submodule_url: 'http://gitlab.com/gitlab-org/gitlab-ce.git') + submodule_links(submodule_item).should == [ 'https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash' ] + end + + it 'should detect https' do + submodule_item.stub(submodule_url: 'https://gitlab.com/gitlab-org/gitlab-ce.git') + submodule_links(submodule_item).should == [ 'https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash' ] + end + + it 'should return original with non-standard url' do + submodule_item.stub(submodule_url: 'http://gitlab.com/gitlab-org/gitlab-ce') + submodule_links(submodule_item).should == [ submodule_item.submodule_url, nil ] + + submodule_item.stub(submodule_url: 'http://gitlab.com/another/gitlab-org/gitlab-ce.git') + submodule_links(submodule_item).should == [ submodule_item.submodule_url, nil ] + end + end + + context 'submodule on unsupported' do + it 'should return original' do + submodule_item.stub(submodule_url: 'http://mygitserver.com/gitlab-org/gitlab-ce') + submodule_links(submodule_item).should == [ submodule_item.submodule_url, nil ] + + submodule_item.stub(submodule_url: 'http://mygitserver.com/gitlab-org/gitlab-ce.git') + submodule_links(submodule_item).should == [ submodule_item.submodule_url, nil ] + end + end + end +end |