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 | 3 | |
4 | 4 | # links to files listing for submodule if submodule is a project on this server |
5 | 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 | 8 | return url, nil unless url =~ /([^\/:]+\/[^\/]+\.git)\Z/ |
11 | 9 | ... | ... |
app/models/repository.rb
... | ... | @@ -188,4 +188,20 @@ class Repository |
188 | 188 | nil |
189 | 189 | end |
190 | 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 | 207 | end | ... | ... |
spec/helpers/submodule_helper_spec.rb
... | ... | @@ -2,8 +2,13 @@ require 'spec_helper' |
2 | 2 | |
3 | 3 | describe SubmoduleHelper do |
4 | 4 | describe 'submodule links' do |
5 | - let(:submodule_item) { double(submodule_url: '', id: 'hash') } | |
5 | + let(:submodule_item) { double(id: 'hash', path: 'rack') } | |
6 | 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 | 13 | context 'submodule on self' do |
9 | 14 | before do |
... | ... | @@ -12,28 +17,28 @@ describe SubmoduleHelper do |
12 | 17 | |
13 | 18 | it 'should detect ssh on standard port' do |
14 | 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 | 21 | submodule_links(submodule_item).should == [ project_path('gitlab-org/gitlab-ce'), project_tree_path('gitlab-org/gitlab-ce', 'hash') ] |
17 | 22 | end |
18 | - | |
23 | + | |
19 | 24 | it 'should detect ssh on non-standard port' do |
20 | 25 | Gitlab.config.gitlab_shell.stub(ssh_port: 2222) |
21 | 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 | 28 | submodule_links(submodule_item).should == [ project_path('gitlab-org/gitlab-ce'), project_tree_path('gitlab-org/gitlab-ce', 'hash') ] |
24 | 29 | end |
25 | 30 | |
26 | 31 | it 'should detect http on standard port' do |
27 | 32 | Gitlab.config.gitlab.stub(port: 80) |
28 | 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 | 35 | submodule_links(submodule_item).should == [ project_path('gitlab-org/gitlab-ce'), project_tree_path('gitlab-org/gitlab-ce', 'hash') ] |
31 | 36 | end |
32 | 37 | |
33 | 38 | it 'should detect http on non-standard port' do |
34 | 39 | Gitlab.config.gitlab.stub(port: 3000) |
35 | 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 | 42 | submodule_links(submodule_item).should == [ project_path('gitlab-org/gitlab-ce'), project_tree_path('gitlab-org/gitlab-ce', 'hash') ] |
38 | 43 | end |
39 | 44 | |
... | ... | @@ -41,69 +46,73 @@ describe SubmoduleHelper do |
41 | 46 | Gitlab.config.gitlab.stub(port: 80) # set this just to be sure |
42 | 47 | Gitlab.config.gitlab.stub(relative_url_root: '/gitlab/root') |
43 | 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 | 50 | submodule_links(submodule_item).should == [ project_path('gitlab-org/gitlab-ce'), project_tree_path('gitlab-org/gitlab-ce', 'hash') ] |
46 | 51 | end |
47 | 52 | end |
48 | - | |
53 | + | |
49 | 54 | context 'submodule on github.com' do |
50 | 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 | 57 | submodule_links(submodule_item).should == [ 'https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash' ] |
53 | 58 | end |
54 | - | |
59 | + | |
55 | 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 | 62 | submodule_links(submodule_item).should == [ 'https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash' ] |
58 | 63 | end |
59 | - | |
64 | + | |
60 | 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 | 67 | submodule_links(submodule_item).should == [ 'https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash' ] |
63 | 68 | end |
64 | - | |
69 | + | |
65 | 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 | 76 | end |
72 | 77 | end |
73 | - | |
78 | + | |
74 | 79 | context 'submodule on gitlab.com' do |
75 | 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 | 82 | submodule_links(submodule_item).should == [ 'https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash' ] |
78 | 83 | end |
79 | - | |
84 | + | |
80 | 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 | 87 | submodule_links(submodule_item).should == [ 'https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash' ] |
83 | 88 | end |
84 | - | |
89 | + | |
85 | 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 | 92 | submodule_links(submodule_item).should == [ 'https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash' ] |
88 | 93 | end |
89 | - | |
94 | + | |
90 | 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 | 101 | end |
97 | 102 | end |
98 | - | |
103 | + | |
99 | 104 | context 'submodule on unsupported' do |
100 | 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 | 111 | end |
107 | 112 | end |
108 | 113 | end |
114 | + | |
115 | + def stub_url(url) | |
116 | + repo.stub(submodule_url_for: url) | |
117 | + end | |
109 | 118 | end | ... | ... |