Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
bed05a13
Commit
bed05a13
authored
Feb 10, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix submodule_helper specs
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
dee11dad
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
37 deletions
+60
-37
app/helpers/submodule_helper.rb
app/helpers/submodule_helper.rb
+1
-3
app/models/repository.rb
app/models/repository.rb
+16
-0
spec/helpers/submodule_helper_spec.rb
spec/helpers/submodule_helper_spec.rb
+43
-34
No files found.
app/helpers/submodule_helper.rb
View file @
bed05a13
...
...
@@ -3,9 +3,7 @@ module SubmoduleHelper
# links to files listing for submodule if submodule is a project on this server
def
submodule_links
(
submodule_item
)
submodule
=
@repository
.
submodules
(
@ref
)[
submodule_item
.
path
]
url
=
submodule
[
'url'
]
if
submodule
url
=
@repository
.
submodule_url_for
(
@ref
,
submodule_item
.
path
)
return
url
,
nil
unless
url
=~
/([^\/:]+\/[^\/]+\.git)\Z/
...
...
app/models/repository.rb
View file @
bed05a13
...
...
@@ -188,4 +188,20 @@ class Repository
nil
end
end
# Returns url for submodule
#
# Ex.
# @repository.submodule_url_for('master', 'rack')
# # => git@localhost:rack.git
#
def
submodule_url_for
(
ref
,
path
)
if
submodules
.
any?
submodule
=
submodules
(
ref
)[
path
]
if
submodule
submodule
[
'url'
]
end
end
end
end
spec/helpers/submodule_helper_spec.rb
View file @
bed05a13
...
...
@@ -2,8 +2,13 @@ require 'spec_helper'
describe
SubmoduleHelper
do
describe
'submodule links'
do
let
(
:submodule_item
)
{
double
(
submodule_url:
''
,
id:
'hash
'
)
}
let
(
:submodule_item
)
{
double
(
id:
'hash'
,
path:
'rack
'
)
}
let
(
:config
)
{
Gitlab
.
config
.
gitlab
}
let
(
:repo
)
{
double
()
}
before
do
self
.
instance_variable_set
(
:@repository
,
repo
)
end
context
'submodule on self'
do
before
do
...
...
@@ -12,28 +17,28 @@ describe SubmoduleHelper do
it
'should detect ssh on standard port'
do
Gitlab
.
config
.
gitlab
.
stub
(
ssh_port:
22
)
# set this just to be sure
s
ubmodule_item
.
stub
(
submodule_url:
[
config
.
user
,
'@'
,
config
.
host
,
':gitlab-org/gitlab-ce.git'
].
join
(
''
))
s
tub_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
))
s
ubmodule_item
.
stub
(
submodule_url:
[
'ssh://'
,
config
.
user
,
'@'
,
config
.
host
,
':2222/gitlab-org/gitlab-ce.git'
].
join
(
''
))
s
tub_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
))
s
ubmodule_item
.
stub
(
submodule_url:
[
'http://'
,
config
.
host
,
'/gitlab-org/gitlab-ce.git'
].
join
(
''
))
s
tub_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
))
s
ubmodule_item
.
stub
(
submodule_url:
[
'http://'
,
config
.
host
,
':3000/gitlab-org/gitlab-ce.git'
].
join
(
''
))
s
tub_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
...
...
@@ -41,69 +46,73 @@ describe SubmoduleHelper 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
))
s
ubmodule_item
.
stub
(
submodule_url:
[
'http://'
,
config
.
host
,
'/gitlab/root/gitlab-org/gitlab-ce.git'
].
join
(
''
))
s
tub_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
s
ubmodule_item
.
stub
(
submodule_url:
'git@github.com:gitlab-org/gitlab-ce.git'
)
s
tub_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
s
ubmodule_item
.
stub
(
submodule_url:
'http://github.com/gitlab-org/gitlab-ce.git'
)
s
tub_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
s
ubmodule_item
.
stub
(
submodule_url:
'https://github.com/gitlab-org/gitlab-ce.git'
)
s
tub_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
s
ubmodule_item
.
stub
(
submodule_url:
'http://github.com/gitlab-org/gitlab-ce'
)
submodule_links
(
submodule_item
).
should
==
[
submodule_item
.
submodule_url
,
nil
]
s
tub_url
(
'http://github.com/gitlab-org/gitlab-ce'
)
submodule_links
(
submodule_item
).
should
==
[
repo
.
submodule_url_for
,
nil
]
s
ubmodule_item
.
stub
(
submodule_url:
'http://github.com/another/gitlab-org/gitlab-ce.git'
)
submodule_links
(
submodule_item
).
should
==
[
submodule_item
.
submodule_url
,
nil
]
s
tub_url
(
'http://github.com/another/gitlab-org/gitlab-ce.git'
)
submodule_links
(
submodule_item
).
should
==
[
repo
.
submodule_url_for
,
nil
]
end
end
context
'submodule on gitlab.com'
do
it
'should detect ssh'
do
s
ubmodule_item
.
stub
(
submodule_url:
'git@gitlab.com:gitlab-org/gitlab-ce.git'
)
s
tub_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
s
ubmodule_item
.
stub
(
submodule_url:
'http://gitlab.com/gitlab-org/gitlab-ce.git'
)
s
tub_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
s
ubmodule_item
.
stub
(
submodule_url:
'https://gitlab.com/gitlab-org/gitlab-ce.git'
)
s
tub_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
s
ubmodule_item
.
stub
(
submodule_url:
'http://gitlab.com/gitlab-org/gitlab-ce'
)
submodule_links
(
submodule_item
).
should
==
[
submodule_item
.
submodule_url
,
nil
]
s
tub_url
(
'http://gitlab.com/gitlab-org/gitlab-ce'
)
submodule_links
(
submodule_item
).
should
==
[
repo
.
submodule_url_for
,
nil
]
s
ubmodule_item
.
stub
(
submodule_url:
'http://gitlab.com/another/gitlab-org/gitlab-ce.git'
)
submodule_links
(
submodule_item
).
should
==
[
submodule_item
.
submodule_url
,
nil
]
s
tub_url
(
'http://gitlab.com/another/gitlab-org/gitlab-ce.git'
)
submodule_links
(
submodule_item
).
should
==
[
repo
.
submodule_url_for
,
nil
]
end
end
context
'submodule on unsupported'
do
it
'should return original'
do
s
ubmodule_item
.
stub
(
submodule_url:
'http://mygitserver.com/gitlab-org/gitlab-ce'
)
submodule_links
(
submodule_item
).
should
==
[
submodule_item
.
submodule_url
,
nil
]
s
tub_url
(
'http://mygitserver.com/gitlab-org/gitlab-ce'
)
submodule_links
(
submodule_item
).
should
==
[
repo
.
submodule_url_for
,
nil
]
s
ubmodule_item
.
stub
(
submodule_url:
'http://mygitserver.com/gitlab-org/gitlab-ce.git'
)
submodule_links
(
submodule_item
).
should
==
[
submodule_item
.
submodule_url
,
nil
]
s
tub_url
(
'http://mygitserver.com/gitlab-org/gitlab-ce.git'
)
submodule_links
(
submodule_item
).
should
==
[
repo
.
submodule_url_for
,
nil
]
end
end
end
def
stub_url
(
url
)
repo
.
stub
(
submodule_url_for:
url
)
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment