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
128a5e41
Commit
128a5e41
authored
Dec 19, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expose method that returns GitLab API paths
parent
32fbc12c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
0 deletions
+44
-0
lib/api/api.rb
lib/api/api.rb
+8
-0
spec/lib/api/api_spec.rb
spec/lib/api/api_spec.rb
+36
-0
No files found.
lib/api/api.rb
View file @
128a5e41
...
...
@@ -10,6 +10,14 @@ module API
NAMESPACE_OR_PROJECT_REQUIREMENTS
=
{
id:
NO_SLASH_URL_PART_REGEX
}.
freeze
COMMIT_ENDPOINT_REQUIREMENTS
=
NAMESPACE_OR_PROJECT_REQUIREMENTS
.
merge
(
sha:
NO_SLASH_URL_PART_REGEX
).
freeze
def
self
.
root_path
(
version:
'v4'
)
unless
versions
.
include?
(
version
)
raise
ArgumentError
,
'Unknown API version!'
end
File
.
join
(
'/'
,
prefix
.
to_s
,
version
.
to_s
)
end
insert_before
Grape
::
Middleware
::
Error
,
GrapeLogging
::
Middleware
::
RequestLogger
,
logger:
Logger
.
new
(
LOG_FILENAME
),
...
...
spec/lib/api/api_spec.rb
0 → 100644
View file @
128a5e41
require
'spec_helper'
describe
API
::
API
do
describe
'.prefix'
do
it
'has a prefix defined'
do
expect
(
described_class
.
prefix
).
to
eq
:api
end
end
describe
'.version'
do
it
'uses most recent version of the API'
do
expect
(
described_class
.
version
).
to
eq
'v4'
end
end
describe
'.versions'
do
it
'returns all available versions'
do
expect
(
described_class
.
versions
).
to
eq
[
'v3'
,
'v4'
]
end
end
describe
'.root_path'
do
it
'returns predefined API version path'
do
expect
(
described_class
.
root_path
).
to
eq
'/api/v4'
end
it
'returns a version provided as keyword argument'
do
expect
(
described_class
.
root_path
(
version:
'v3'
)).
to
eq
'/api/v3'
end
it
'raises an error if version is not known'
do
expect
{
described_class
.
root_path
(
version:
'v10'
)
}
.
to
raise_error
ArgumentError
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