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
f93607a3
Commit
f93607a3
authored
Nov 15, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get rid of light url builder and fix wrong spec
parent
ca6da6ea
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
113 deletions
+91
-113
lib/gitlab/light_url_builder.rb
lib/gitlab/light_url_builder.rb
+0
-67
spec/lib/gitlab/url_builder_spec.rb
spec/lib/gitlab/url_builder_spec.rb
+91
-46
No files found.
lib/gitlab/light_url_builder.rb
deleted
100644 → 0
View file @
ca6da6ea
module
Gitlab
# Similar to UrlBuilder, but using IDs to avoid querying the DB for objects
# Useful for using in conjunction with Arel queries.
class
LightUrlBuilder
include
Gitlab
::
Routing
.
url_helpers
include
GitlabRoutingHelper
include
ActionView
::
RecordIdentifier
def
self
.
build
(
*
args
)
new
(
*
args
).
url
end
def
initialize
(
entity
:,
project:
nil
,
id
:,
opts:
{})
@entity
=
entity
@project
=
project
@id
=
id
@opts
=
opts
end
def
url
url_method
=
"
#{
@entity
}
_url"
raise
NotImplementedError
.
new
(
"No Light URL builder defined for
#{
@entity
}
"
)
unless
respond_to?
(
url_method
)
public_send
(
url_method
)
end
def
issue_url
namespace_project_issue_url
({
namespace_id:
@project
.
namespace
,
project_id:
@project
,
id:
@id
}.
merge!
(
@opts
))
end
def
user_avatar_url
User
.
find
(
@id
).
avatar_url
end
def
commit_url
namespace_project_commit_url
({
namespace_id:
@project
.
namespace
,
project_id:
@project
,
id:
@id
}.
merge!
(
@opts
))
end
def
merge_request_url
namespace_project_merge_request_url
({
namespace_id:
@project
.
namespace
,
project_id:
@project
,
id:
@id
}.
merge!
(
@opts
))
end
def
branch_url
namespace_project_commit_url
(
@project
.
namespace
,
@project
,
@id
)
end
def
user_url
Gitlab
::
Routing
.
url_helpers
.
user_url
(
@id
)
end
def
build_url
namespace_project_build_url
(
@project
.
namespace
,
@project
,
@id
)
end
end
end
spec/lib/gitlab/url_builder_spec.rb
View file @
f93607a3
require
'spec_helper'
require
'spec_helper'
describe
Gitlab
::
LightUrlBuilder
,
lib:
true
do
describe
Gitlab
::
UrlBuilder
,
lib:
true
do
context
'when passing a Commit'
do
describe
'.build'
do
it
'returns a proper URL'
do
context
'when passing a Commit'
do
commit
=
build_stubbed
(
:commit
)
it
'returns a proper URL'
do
commit
=
build_stubbed
(
:commit
)
url
=
described_class
.
build
(
entity: :commit
,
project:
commit
.
project
,
id:
commit
.
id
)
url
=
described_class
.
build
(
commit
)
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
commit
.
project
.
path_with_namespace
}
/commit/
#{
commit
.
id
}
"
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
commit
.
project
.
path_with_namespace
}
/commit/
#{
commit
.
id
}
"
end
end
end
end
context
'when passing an Issue'
do
context
'when passing an Issue'
do
it
'returns a proper URL'
do
it
'returns a proper URL'
do
issue
=
build_stubbed
(
:issue
,
iid:
42
)
issue
=
build_stubbed
(
:issue
,
iid:
42
)
url
=
described_class
.
build
(
entity: :issue
,
project:
issue
.
project
,
id:
issue
.
iid
)
url
=
described_class
.
build
(
issue
)
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
issue
.
project
.
path_with_namespace
}
/issues/
#{
issue
.
iid
}
"
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
issue
.
project
.
path_with_namespace
}
/issues/
#{
issue
.
iid
}
"
end
end
end
end
context
'when passing a MergeRequest'
do
context
'when passing a MergeRequest'
do
it
'returns a proper URL'
do
it
'returns a proper URL'
do
merge_request
=
build_stubbed
(
:merge_request
,
iid:
42
)
merge_request
=
build_stubbed
(
:merge_request
,
iid:
42
)
url
=
described_class
.
build
(
entity: :merge_request
,
project:
merge_request
.
project
,
id:
merge_request
.
iid
)
url
=
described_class
.
build
(
merge_request
)
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
merge_request
.
project
.
path_with_namespace
}
/merge_requests/
#{
merge_request
.
iid
}
"
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
merge_request
.
project
.
path_with_namespace
}
/merge_requests/
#{
merge_request
.
iid
}
"
end
end
end
end
context
'when passing a build'
do
context
'when passing a Note'
do
it
'returns a proper URL'
do
context
'on a Commit'
do
build
=
build_stubbed
(
:ci_build
,
project:
build_stubbed
(
:empty_project
))
it
'returns a proper URL'
do
note
=
build_stubbed
(
:note_on_commit
)
url
=
described_class
.
build
(
entity: :build
,
project:
build
.
project
,
id:
build
.
id
)
url
=
described_class
.
build
(
note
)
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
build
.
project
.
path_with_namespace
}
/builds/
#{
build
.
id
}
"
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
note
.
project
.
path_with_namespace
}
/commit/
#{
note
.
commit_id
}
#note_
#{
note
.
id
}
"
end
end
end
end
context
'when passing a branch'
do
context
'on a Commit Diff'
do
it
'returns a proper URL'
do
it
'returns a proper URL'
do
branch
=
'branch_name'
note
=
build_stubbed
(
:diff_note_on_commit
)
project
=
build_stubbed
(
:empty_project
)
url
=
described_class
.
build
(
entity: :branch
,
project:
project
,
id:
branch
)
url
=
described_class
.
build
(
note
)
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
project
.
path_with_namespace
}
/commits/
#{
branch
}
"
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
note
.
project
.
path_with_namespace
}
/commit/
#{
note
.
commit_id
}
#note_
#{
note
.
id
}
"
end
end
end
end
context
'on a User'
do
context
'on an Issue'
do
it
'returns a proper URL'
do
it
'returns a proper URL'
do
user
=
build_stubbed
(
:user
)
issue
=
create
(
:issue
,
iid:
42
)
note
=
build_stubbed
(
:note_on_issue
,
noteable:
issue
)
url
=
described_class
.
build
(
entity: :user
,
id:
user
.
usernam
e
)
url
=
described_class
.
build
(
not
e
)
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
user
.
username
}
"
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
issue
.
project
.
path_with_namespace
}
/issues/
#{
issue
.
iid
}
#note_
#{
note
.
id
}
"
end
end
end
end
context
'on a MergeRequest'
do
it
'returns a proper URL'
do
merge_request
=
create
(
:merge_request
,
iid:
42
)
note
=
build_stubbed
(
:note_on_merge_request
,
noteable:
merge_request
)
context
'on a user avatar'
do
url
=
described_class
.
build
(
note
)
it
'returns a proper URL'
do
user
=
create
(
:user
)
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
merge_request
.
project
.
path_with_namespace
}
/merge_requests/
#{
merge_request
.
iid
}
#note_
#{
note
.
id
}
"
end
end
context
'on a MergeRequest Diff'
do
it
'returns a proper URL'
do
merge_request
=
create
(
:merge_request
,
iid:
42
)
note
=
build_stubbed
(
:diff_note_on_merge_request
,
noteable:
merge_request
)
url
=
described_class
.
build
(
note
)
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
merge_request
.
project
.
path_with_namespace
}
/merge_requests/
#{
merge_request
.
iid
}
#note_
#{
note
.
id
}
"
end
end
context
'on a ProjectSnippet'
do
it
'returns a proper URL'
do
project_snippet
=
create
(
:project_snippet
)
note
=
build_stubbed
(
:note_on_project_snippet
,
noteable:
project_snippet
)
url
=
described_class
.
build
(
note
)
expect
(
url
).
to
eq
"
#{
Settings
.
gitlab
[
'url'
]
}
/
#{
project_snippet
.
project
.
path_with_namespace
}
/snippets/
#{
note
.
noteable_id
}
#note_
#{
note
.
id
}
"
end
end
context
'on another object'
do
it
'returns a proper URL'
do
project
=
build_stubbed
(
:project
)
expect
{
described_class
.
build
(
project
)
}.
to
raise_error
(
NotImplementedError
,
'No URL builder defined for Project'
)
end
end
end
url
=
described_class
.
build
(
entity: :user_avatar
,
id:
user
.
id
)
context
'when passing a WikiPage'
do
it
'returns a proper URL'
do
wiki_page
=
build
(
:wiki_page
)
url
=
described_class
.
build
(
wiki_page
)
expect
(
url
).
to
eq
user
.
avatar_url
expect
(
url
).
to
eq
"
#{
Gitlab
.
config
.
gitlab
.
url
}#{
wiki_page
.
wiki
.
wiki_base_path
}
/
#{
wiki_page
.
slug
}
"
end
end
end
end
end
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