Commit bed05a1381fab0b7c74817f68aac8e18c60c6a25
1 parent
dee11dad
Exists in
spb-stable
and in
3 other branches
Fix submodule_helper specs
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
3 changed files
with
60 additions
and
37 deletions
Show diff stats
app/helpers/submodule_helper.rb
| @@ -3,9 +3,7 @@ module SubmoduleHelper | @@ -3,9 +3,7 @@ module SubmoduleHelper | ||
| 3 | 3 | ||
| 4 | # links to files listing for submodule if submodule is a project on this server | 4 | # links to files listing for submodule if submodule is a project on this server |
| 5 | def submodule_links(submodule_item) | 5 | def submodule_links(submodule_item) |
| 6 | - submodule = @repository.submodules(@ref)[submodule_item.path] | ||
| 7 | - | ||
| 8 | - url = submodule['url'] if submodule | 6 | + url = @repository.submodule_url_for(@ref, submodule_item.path) |
| 9 | 7 | ||
| 10 | return url, nil unless url =~ /([^\/:]+\/[^\/]+\.git)\Z/ | 8 | return url, nil unless url =~ /([^\/:]+\/[^\/]+\.git)\Z/ |
| 11 | 9 |
app/models/repository.rb
| @@ -188,4 +188,20 @@ class Repository | @@ -188,4 +188,20 @@ class Repository | ||
| 188 | nil | 188 | nil |
| 189 | end | 189 | end |
| 190 | end | 190 | end |
| 191 | + | ||
| 192 | + # Returns url for submodule | ||
| 193 | + # | ||
| 194 | + # Ex. | ||
| 195 | + # @repository.submodule_url_for('master', 'rack') | ||
| 196 | + # # => git@localhost:rack.git | ||
| 197 | + # | ||
| 198 | + def submodule_url_for(ref, path) | ||
| 199 | + if submodules.any? | ||
| 200 | + submodule = submodules(ref)[path] | ||
| 201 | + | ||
| 202 | + if submodule | ||
| 203 | + submodule['url'] | ||
| 204 | + end | ||
| 205 | + end | ||
| 206 | + end | ||
| 191 | end | 207 | end |
spec/helpers/submodule_helper_spec.rb
| @@ -2,8 +2,13 @@ require 'spec_helper' | @@ -2,8 +2,13 @@ require 'spec_helper' | ||
| 2 | 2 | ||
| 3 | describe SubmoduleHelper do | 3 | describe SubmoduleHelper do |
| 4 | describe 'submodule links' do | 4 | describe 'submodule links' do |
| 5 | - let(:submodule_item) { double(submodule_url: '', id: 'hash') } | 5 | + let(:submodule_item) { double(id: 'hash', path: 'rack') } |
| 6 | let(:config) { Gitlab.config.gitlab } | 6 | let(:config) { Gitlab.config.gitlab } |
| 7 | + let(:repo) { double() } | ||
| 8 | + | ||
| 9 | + before do | ||
| 10 | + self.instance_variable_set(:@repository, repo) | ||
| 11 | + end | ||
| 7 | 12 | ||
| 8 | context 'submodule on self' do | 13 | context 'submodule on self' do |
| 9 | before do | 14 | before do |
| @@ -12,28 +17,28 @@ describe SubmoduleHelper do | @@ -12,28 +17,28 @@ describe SubmoduleHelper do | ||
| 12 | 17 | ||
| 13 | it 'should detect ssh on standard port' do | 18 | it 'should detect ssh on standard port' do |
| 14 | Gitlab.config.gitlab.stub(ssh_port: 22) # set this just to be sure | 19 | Gitlab.config.gitlab.stub(ssh_port: 22) # set this just to be sure |
| 15 | - submodule_item.stub(submodule_url: [ config.user, '@', config.host, ':gitlab-org/gitlab-ce.git' ].join('')) | 20 | + stub_url([ config.user, '@', config.host, ':gitlab-org/gitlab-ce.git' ].join('')) |
| 16 | submodule_links(submodule_item).should == [ project_path('gitlab-org/gitlab-ce'), project_tree_path('gitlab-org/gitlab-ce', 'hash') ] | 21 | submodule_links(submodule_item).should == [ project_path('gitlab-org/gitlab-ce'), project_tree_path('gitlab-org/gitlab-ce', 'hash') ] |
| 17 | end | 22 | end |
| 18 | - | 23 | + |
| 19 | it 'should detect ssh on non-standard port' do | 24 | it 'should detect ssh on non-standard port' do |
| 20 | Gitlab.config.gitlab_shell.stub(ssh_port: 2222) | 25 | Gitlab.config.gitlab_shell.stub(ssh_port: 2222) |
| 21 | Gitlab.config.gitlab_shell.stub(ssh_path_prefix: Settings.send(:build_gitlab_shell_ssh_path_prefix)) | 26 | Gitlab.config.gitlab_shell.stub(ssh_path_prefix: Settings.send(:build_gitlab_shell_ssh_path_prefix)) |
| 22 | - submodule_item.stub(submodule_url: [ 'ssh://', config.user, '@', config.host, ':2222/gitlab-org/gitlab-ce.git' ].join('')) | 27 | + stub_url([ 'ssh://', config.user, '@', config.host, ':2222/gitlab-org/gitlab-ce.git' ].join('')) |
| 23 | submodule_links(submodule_item).should == [ project_path('gitlab-org/gitlab-ce'), project_tree_path('gitlab-org/gitlab-ce', 'hash') ] | 28 | submodule_links(submodule_item).should == [ project_path('gitlab-org/gitlab-ce'), project_tree_path('gitlab-org/gitlab-ce', 'hash') ] |
| 24 | end | 29 | end |
| 25 | 30 | ||
| 26 | it 'should detect http on standard port' do | 31 | it 'should detect http on standard port' do |
| 27 | Gitlab.config.gitlab.stub(port: 80) | 32 | Gitlab.config.gitlab.stub(port: 80) |
| 28 | Gitlab.config.gitlab.stub(url: Settings.send(:build_gitlab_url)) | 33 | Gitlab.config.gitlab.stub(url: Settings.send(:build_gitlab_url)) |
| 29 | - submodule_item.stub(submodule_url: [ 'http://', config.host, '/gitlab-org/gitlab-ce.git' ].join('')) | 34 | + stub_url([ 'http://', config.host, '/gitlab-org/gitlab-ce.git' ].join('')) |
| 30 | submodule_links(submodule_item).should == [ project_path('gitlab-org/gitlab-ce'), project_tree_path('gitlab-org/gitlab-ce', 'hash') ] | 35 | submodule_links(submodule_item).should == [ project_path('gitlab-org/gitlab-ce'), project_tree_path('gitlab-org/gitlab-ce', 'hash') ] |
| 31 | end | 36 | end |
| 32 | 37 | ||
| 33 | it 'should detect http on non-standard port' do | 38 | it 'should detect http on non-standard port' do |
| 34 | Gitlab.config.gitlab.stub(port: 3000) | 39 | Gitlab.config.gitlab.stub(port: 3000) |
| 35 | Gitlab.config.gitlab.stub(url: Settings.send(:build_gitlab_url)) | 40 | Gitlab.config.gitlab.stub(url: Settings.send(:build_gitlab_url)) |
| 36 | - submodule_item.stub(submodule_url: [ 'http://', config.host, ':3000/gitlab-org/gitlab-ce.git' ].join('')) | 41 | + stub_url([ 'http://', config.host, ':3000/gitlab-org/gitlab-ce.git' ].join('')) |
| 37 | submodule_links(submodule_item).should == [ project_path('gitlab-org/gitlab-ce'), project_tree_path('gitlab-org/gitlab-ce', 'hash') ] | 42 | submodule_links(submodule_item).should == [ project_path('gitlab-org/gitlab-ce'), project_tree_path('gitlab-org/gitlab-ce', 'hash') ] |
| 38 | end | 43 | end |
| 39 | 44 | ||
| @@ -41,69 +46,73 @@ describe SubmoduleHelper do | @@ -41,69 +46,73 @@ describe SubmoduleHelper do | ||
| 41 | Gitlab.config.gitlab.stub(port: 80) # set this just to be sure | 46 | Gitlab.config.gitlab.stub(port: 80) # set this just to be sure |
| 42 | Gitlab.config.gitlab.stub(relative_url_root: '/gitlab/root') | 47 | Gitlab.config.gitlab.stub(relative_url_root: '/gitlab/root') |
| 43 | Gitlab.config.gitlab.stub(url: Settings.send(:build_gitlab_url)) | 48 | Gitlab.config.gitlab.stub(url: Settings.send(:build_gitlab_url)) |
| 44 | - submodule_item.stub(submodule_url: [ 'http://', config.host, '/gitlab/root/gitlab-org/gitlab-ce.git' ].join('')) | 49 | + stub_url([ 'http://', config.host, '/gitlab/root/gitlab-org/gitlab-ce.git' ].join('')) |
| 45 | submodule_links(submodule_item).should == [ project_path('gitlab-org/gitlab-ce'), project_tree_path('gitlab-org/gitlab-ce', 'hash') ] | 50 | submodule_links(submodule_item).should == [ project_path('gitlab-org/gitlab-ce'), project_tree_path('gitlab-org/gitlab-ce', 'hash') ] |
| 46 | end | 51 | end |
| 47 | end | 52 | end |
| 48 | - | 53 | + |
| 49 | context 'submodule on github.com' do | 54 | context 'submodule on github.com' do |
| 50 | it 'should detect ssh' do | 55 | it 'should detect ssh' do |
| 51 | - submodule_item.stub(submodule_url: 'git@github.com:gitlab-org/gitlab-ce.git') | 56 | + stub_url('git@github.com:gitlab-org/gitlab-ce.git') |
| 52 | submodule_links(submodule_item).should == [ 'https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash' ] | 57 | submodule_links(submodule_item).should == [ 'https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash' ] |
| 53 | end | 58 | end |
| 54 | - | 59 | + |
| 55 | it 'should detect http' do | 60 | it 'should detect http' do |
| 56 | - submodule_item.stub(submodule_url: 'http://github.com/gitlab-org/gitlab-ce.git') | 61 | + stub_url('http://github.com/gitlab-org/gitlab-ce.git') |
| 57 | submodule_links(submodule_item).should == [ 'https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash' ] | 62 | submodule_links(submodule_item).should == [ 'https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash' ] |
| 58 | end | 63 | end |
| 59 | - | 64 | + |
| 60 | it 'should detect https' do | 65 | it 'should detect https' do |
| 61 | - submodule_item.stub(submodule_url: 'https://github.com/gitlab-org/gitlab-ce.git') | 66 | + stub_url('https://github.com/gitlab-org/gitlab-ce.git') |
| 62 | submodule_links(submodule_item).should == [ 'https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash' ] | 67 | submodule_links(submodule_item).should == [ 'https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash' ] |
| 63 | end | 68 | end |
| 64 | - | 69 | + |
| 65 | it 'should return original with non-standard url' do | 70 | it 'should return original with non-standard url' do |
| 66 | - submodule_item.stub(submodule_url: 'http://github.com/gitlab-org/gitlab-ce') | ||
| 67 | - submodule_links(submodule_item).should == [ submodule_item.submodule_url, nil ] | 71 | + stub_url('http://github.com/gitlab-org/gitlab-ce') |
| 72 | + submodule_links(submodule_item).should == [ repo.submodule_url_for, nil ] | ||
| 68 | 73 | ||
| 69 | - submodule_item.stub(submodule_url: 'http://github.com/another/gitlab-org/gitlab-ce.git') | ||
| 70 | - submodule_links(submodule_item).should == [ submodule_item.submodule_url, nil ] | 74 | + stub_url('http://github.com/another/gitlab-org/gitlab-ce.git') |
| 75 | + submodule_links(submodule_item).should == [ repo.submodule_url_for, nil ] | ||
| 71 | end | 76 | end |
| 72 | end | 77 | end |
| 73 | - | 78 | + |
| 74 | context 'submodule on gitlab.com' do | 79 | context 'submodule on gitlab.com' do |
| 75 | it 'should detect ssh' do | 80 | it 'should detect ssh' do |
| 76 | - submodule_item.stub(submodule_url: 'git@gitlab.com:gitlab-org/gitlab-ce.git') | 81 | + stub_url('git@gitlab.com:gitlab-org/gitlab-ce.git') |
| 77 | submodule_links(submodule_item).should == [ 'https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash' ] | 82 | submodule_links(submodule_item).should == [ 'https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash' ] |
| 78 | end | 83 | end |
| 79 | - | 84 | + |
| 80 | it 'should detect http' do | 85 | it 'should detect http' do |
| 81 | - submodule_item.stub(submodule_url: 'http://gitlab.com/gitlab-org/gitlab-ce.git') | 86 | + stub_url('http://gitlab.com/gitlab-org/gitlab-ce.git') |
| 82 | submodule_links(submodule_item).should == [ 'https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash' ] | 87 | submodule_links(submodule_item).should == [ 'https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash' ] |
| 83 | end | 88 | end |
| 84 | - | 89 | + |
| 85 | it 'should detect https' do | 90 | it 'should detect https' do |
| 86 | - submodule_item.stub(submodule_url: 'https://gitlab.com/gitlab-org/gitlab-ce.git') | 91 | + stub_url('https://gitlab.com/gitlab-org/gitlab-ce.git') |
| 87 | submodule_links(submodule_item).should == [ 'https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash' ] | 92 | submodule_links(submodule_item).should == [ 'https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash' ] |
| 88 | end | 93 | end |
| 89 | - | 94 | + |
| 90 | it 'should return original with non-standard url' do | 95 | it 'should return original with non-standard url' do |
| 91 | - submodule_item.stub(submodule_url: 'http://gitlab.com/gitlab-org/gitlab-ce') | ||
| 92 | - submodule_links(submodule_item).should == [ submodule_item.submodule_url, nil ] | 96 | + stub_url('http://gitlab.com/gitlab-org/gitlab-ce') |
| 97 | + submodule_links(submodule_item).should == [ repo.submodule_url_for, nil ] | ||
| 93 | 98 | ||
| 94 | - submodule_item.stub(submodule_url: 'http://gitlab.com/another/gitlab-org/gitlab-ce.git') | ||
| 95 | - submodule_links(submodule_item).should == [ submodule_item.submodule_url, nil ] | 99 | + stub_url('http://gitlab.com/another/gitlab-org/gitlab-ce.git') |
| 100 | + submodule_links(submodule_item).should == [ repo.submodule_url_for, nil ] | ||
| 96 | end | 101 | end |
| 97 | end | 102 | end |
| 98 | - | 103 | + |
| 99 | context 'submodule on unsupported' do | 104 | context 'submodule on unsupported' do |
| 100 | it 'should return original' do | 105 | it 'should return original' do |
| 101 | - submodule_item.stub(submodule_url: 'http://mygitserver.com/gitlab-org/gitlab-ce') | ||
| 102 | - submodule_links(submodule_item).should == [ submodule_item.submodule_url, nil ] | 106 | + stub_url('http://mygitserver.com/gitlab-org/gitlab-ce') |
| 107 | + submodule_links(submodule_item).should == [ repo.submodule_url_for, nil ] | ||
| 103 | 108 | ||
| 104 | - submodule_item.stub(submodule_url: 'http://mygitserver.com/gitlab-org/gitlab-ce.git') | ||
| 105 | - submodule_links(submodule_item).should == [ submodule_item.submodule_url, nil ] | 109 | + stub_url('http://mygitserver.com/gitlab-org/gitlab-ce.git') |
| 110 | + submodule_links(submodule_item).should == [ repo.submodule_url_for, nil ] | ||
| 106 | end | 111 | end |
| 107 | end | 112 | end |
| 108 | end | 113 | end |
| 114 | + | ||
| 115 | + def stub_url(url) | ||
| 116 | + repo.stub(submodule_url_for: url) | ||
| 117 | + end | ||
| 109 | end | 118 | end |