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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
4b413ac0
Commit
4b413ac0
authored
Jul 21, 2020
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor snippet routes
parent
8214da07
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
37 deletions
+46
-37
app/helpers/gitlab_routing_helper.rb
app/helpers/gitlab_routing_helper.rb
+5
-17
app/presenters/snippet_blob_presenter.rb
app/presenters/snippet_blob_presenter.rb
+1
-1
spec/helpers/gitlab_routing_helper_spec.rb
spec/helpers/gitlab_routing_helper_spec.rb
+40
-19
No files found.
app/helpers/gitlab_routing_helper.rb
View file @
4b413ac0
...
...
@@ -271,7 +271,7 @@ module GitlabRoutingHelper
end
end
def
gitlab_raw_snippet_blob_url
(
snippet
,
path
,
ref
=
nil
)
def
gitlab_raw_snippet_blob_url
(
snippet
,
path
,
ref
=
nil
,
**
options
)
params
=
{
snippet_id:
snippet
,
ref:
ref
||
snippet
.
repository
.
root_ref
,
...
...
@@ -279,26 +279,14 @@ module GitlabRoutingHelper
}
if
snippet
.
is_a?
(
ProjectSnippet
)
project_snippet_blob_raw_url
(
snippet
.
project
,
param
s
)
project_snippet_blob_raw_url
(
snippet
.
project
,
**
params
,
**
option
s
)
else
snippet_blob_raw_url
(
param
s
)
snippet_blob_raw_url
(
**
params
,
**
option
s
)
end
end
def
gitlab_raw_snippet_blob_path
(
blob
,
ref
=
nil
)
snippet
=
blob
.
container
params
=
{
snippet_id:
snippet
,
ref:
ref
||
blob
.
repository
.
root_ref
,
path:
blob
.
path
}
if
snippet
.
is_a?
(
ProjectSnippet
)
project_snippet_blob_raw_path
(
snippet
.
project
,
params
)
else
snippet_blob_raw_path
(
params
)
end
def
gitlab_raw_snippet_blob_path
(
snippet
,
path
,
ref
=
nil
,
**
options
)
gitlab_raw_snippet_blob_url
(
snippet
,
path
,
ref
,
only_path:
true
,
**
options
)
end
def
gitlab_snippet_notes_path
(
snippet
,
*
args
)
...
...
app/presenters/snippet_blob_presenter.rb
View file @
4b413ac0
...
...
@@ -17,7 +17,7 @@ class SnippetBlobPresenter < BlobPresenter
end
def
raw_path
return
gitlab_raw_snippet_blob_path
(
blob
)
if
snippet_multiple_files?
return
gitlab_raw_snippet_blob_path
(
snippet
,
blob
.
path
)
if
snippet_multiple_files?
gitlab_raw_snippet_path
(
snippet
)
end
...
...
spec/helpers/gitlab_routing_helper_spec.rb
View file @
4b413ac0
...
...
@@ -182,58 +182,79 @@ RSpec.describe GitlabRoutingHelper do
end
describe
'#gitlab_raw_snippet_blob_path'
do
let
(
:snippet
)
{
personal_snippet
}
let
(
:blob
)
{
snippet
.
blobs
.
first
}
let
(
:ref
)
{
'test-ref'
}
let
(
:args
)
{
{}
}
subject
{
gitlab_raw_snippet_blob_path
(
snippet
,
blob
.
path
,
ref
,
args
)
}
it_behaves_like
'snippet blob raw path'
context
'when an argument is set'
do
let
(
:args
)
{
{
inline:
true
}
}
it_behaves_like
'snippet blob raw path'
do
subject
{
gitlab_raw_snippet_blob_path
(
blob
,
ref
)
}
it
{
expect
(
subject
).
to
eq
(
"/-/snippets/
#{
personal_snippet
.
id
}
/raw/
#{
ref
}
/
#{
blob
.
path
}
?inline=true"
)
}
end
context
'without a ref'
do
let
(
:
blob
)
{
personal_snippet
.
blobs
.
first
}
let
(
:ref
)
{
blob
.
repository
.
root_ref
}
let
(
:
ref
)
{
nil
}
let
(
:
expected_
ref
)
{
blob
.
repository
.
root_ref
}
it
'uses the root ref'
do
expect
(
gitlab_raw_snippet_blob_path
(
blob
)).
to
eq
(
"/-/snippets/
#{
personal_snippet
.
id
}
/raw/
#{
ref
}
/
#{
blob
.
path
}
"
)
expect
(
subject
).
to
eq
(
"/-/snippets/
#{
personal_snippet
.
id
}
/raw/
#{
expected_
ref
}
/
#{
blob
.
path
}
"
)
end
end
end
describe
'#gitlab_raw_snippet_url'
do
it
'returns the raw personal snippet url'
do
expect
(
gitlab_raw_snippet_url
(
personal_snippet
)).
to
eq
(
"http://test.host/snippets/
#{
personal_snippet
.
id
}
/raw"
)
end
it
'returns the raw project snippet url'
do
expect
(
gitlab_raw_snippet_url
(
project_snippet
)).
to
eq
(
"http://test.host/
#{
project_snippet
.
project
.
full_path
}
/snippets/
#{
project_snippet
.
id
}
/raw"
)
end
end
describe
'#gitlab_raw_snippet_blob_url'
do
let
(
:blob
)
{
snippet
.
blobs
.
first
}
let
(
:ref
)
{
'snippet-test-ref'
}
let
(
:args
)
{
{}
}
subject
{
gitlab_raw_snippet_blob_url
(
snippet
,
blob
.
path
,
ref
,
args
)
}
context
'for a PersonalSnippet'
do
let
(
:snippet
)
{
personal_snippet
}
it
{
expect
(
gitlab_raw_snippet_blob_url
(
snippet
,
blob
.
path
,
ref
)
).
to
eq
(
"http://test.host/-/snippets/
#{
snippet
.
id
}
/raw/
#{
ref
}
/
#{
blob
.
path
}
"
)
}
it
{
expect
(
subject
).
to
eq
(
"http://test.host/-/snippets/
#{
snippet
.
id
}
/raw/
#{
ref
}
/
#{
blob
.
path
}
"
)
}
end
context
'for a ProjectSnippet'
do
let
(
:snippet
)
{
project_snippet
}
it
{
expect
(
gitlab_raw_snippet_blob_url
(
snippet
,
blob
.
path
,
ref
)).
to
eq
(
"http://test.host/
#{
snippet
.
project
.
full_path
}
/-/snippets/
#{
snippet
.
id
}
/raw/
#{
ref
}
/
#{
blob
.
path
}
"
)
}
it
{
expect
(
subject
).
to
eq
(
"http://test.host/
#{
snippet
.
project
.
full_path
}
/-/snippets/
#{
snippet
.
id
}
/raw/
#{
ref
}
/
#{
blob
.
path
}
"
)
}
end
context
'when an argument is set'
do
let
(
:args
)
{
{
inline:
true
}
}
let
(
:snippet
)
{
personal_snippet
}
it
{
expect
(
subject
).
to
eq
(
"http://test.host/-/snippets/
#{
snippet
.
id
}
/raw/
#{
ref
}
/
#{
blob
.
path
}
?inline=true"
)
}
end
context
'without a ref'
do
let
(
:snippet
)
{
personal_snippet
}
let
(
:ref
)
{
snippet
.
repository
.
root_ref
}
let
(
:ref
)
{
nil
}
let
(
:expected_ref
)
{
snippet
.
repository
.
root_ref
}
it
'uses the root ref'
do
expect
(
gitlab_raw_snippet_blob_url
(
snippet
,
blob
.
path
)).
to
eq
(
"http://test.host/-/snippets/
#{
snippet
.
id
}
/raw/
#{
ref
}
/
#{
blob
.
path
}
"
)
expect
(
subject
).
to
eq
(
"http://test.host/-/snippets/
#{
snippet
.
id
}
/raw/
#{
expected_
ref
}
/
#{
blob
.
path
}
"
)
end
end
end
describe
'#gitlab_raw_snippet_url'
do
it
'returns the raw personal snippet url'
do
expect
(
gitlab_raw_snippet_url
(
personal_snippet
)).
to
eq
(
"http://test.host/snippets/
#{
personal_snippet
.
id
}
/raw"
)
end
it
'returns the raw project snippet url'
do
expect
(
gitlab_raw_snippet_url
(
project_snippet
)).
to
eq
(
"http://test.host/
#{
project_snippet
.
project
.
full_path
}
/snippets/
#{
project_snippet
.
id
}
/raw"
)
end
end
describe
'#gitlab_snippet_notes_path'
do
it
'returns the notes path for the personal snippet'
do
expect
(
gitlab_snippet_notes_path
(
personal_snippet
)).
to
eq
(
"/snippets/
#{
personal_snippet
.
id
}
/notes"
)
...
...
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