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
0af4c56c
Commit
0af4c56c
authored
May 22, 2018
by
Francisco Javier López
Committed by
Douwe Maan
May 22, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix `expose_url` helper does not include custom base url if it is set
parent
73572761
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
4 deletions
+26
-4
changelogs/unreleased/fj-46459-fix-expose-url-when-base-url-set.yml
.../unreleased/fj-46459-fix-expose-url-when-base-url-set.yml
+5
-0
lib/api/helpers/related_resources_helpers.rb
lib/api/helpers/related_resources_helpers.rb
+7
-2
spec/lib/api/helpers/related_resources_helpers_spec.rb
spec/lib/api/helpers/related_resources_helpers_spec.rb
+14
-2
No files found.
changelogs/unreleased/fj-46459-fix-expose-url-when-base-url-set.yml
0 → 100644
View file @
0af4c56c
---
title
:
Fixed bug where generated api urls didn't add the base url if set
merge_request
:
19003
author
:
type
:
fixed
lib/api/helpers/related_resources_helpers.rb
View file @
0af4c56c
...
...
@@ -13,9 +13,14 @@ module API
def
expose_url
(
path
)
url_options
=
Gitlab
::
Application
.
routes
.
default_url_options
protocol
,
host
,
port
=
url_options
.
slice
(
:protocol
,
:host
,
:port
).
values
protocol
,
host
,
port
,
script_name
=
url_options
.
values_at
(
:protocol
,
:host
,
:port
,
:script_name
)
URI
::
Generic
.
build
(
scheme:
protocol
,
host:
host
,
port:
port
,
path:
path
).
to_s
# Using a blank component at the beginning of the join we ensure
# that the resulted path will start with '/'. If the resulted path
# does not start with '/', URI::Generic#build will fail
path_with_script_name
=
File
.
join
(
''
,
[
script_name
,
path
].
select
(
&
:present?
))
URI
::
Generic
.
build
(
scheme:
protocol
,
host:
host
,
port:
port
,
path:
path_with_script_name
).
to_s
end
private
...
...
spec/lib/api/helpers/related_resources_helpers_spec.rb
View file @
0af4c56c
...
...
@@ -9,9 +9,9 @@ describe API::Helpers::RelatedResourcesHelpers do
let
(
:path
)
{
'/api/v4/awesome_endpoint'
}
subject
(
:url
)
{
helpers
.
expose_url
(
path
)
}
def
stub_default_url_options
(
protocol:
'http'
,
host:
'example.com'
,
port:
nil
)
def
stub_default_url_options
(
protocol:
'http'
,
host:
'example.com'
,
port:
nil
,
script_name:
''
)
expect
(
Gitlab
::
Application
.
routes
).
to
receive
(
:default_url_options
)
.
and_return
(
protocol:
protocol
,
host:
host
,
port:
port
)
.
and_return
(
protocol:
protocol
,
host:
host
,
port:
port
,
script_name:
script_name
)
end
it
'respects the protocol if it is HTTP'
do
...
...
@@ -37,5 +37,17 @@ describe API::Helpers::RelatedResourcesHelpers do
is_expected
.
to
start_with
(
'http://example.com:8080/'
)
end
it
'includes the relative_url before the path if it is set'
do
stub_default_url_options
(
script_name:
'/gitlab'
)
is_expected
.
to
start_with
(
'http://example.com/gitlab/api/v4'
)
end
it
'includes the path after the host'
do
stub_default_url_options
is_expected
.
to
start_with
(
'http://example.com/api/v4'
)
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