Commit 128a5e41 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Expose method that returns GitLab API paths

parent 32fbc12c
......@@ -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),
......
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment