diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-12-19 21:44:32 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2019-01-03 16:18:05 +0300 |
commit | f10fe3ae97ade4ad73963b86c9ab2d7e4e021c61 (patch) | |
tree | 20d9a9e3c67d5e38a31e029be51dbdac16785c0e /spec/lib/api | |
parent | 128a5e410f4c51bbbcb1540435d3bea0b9a9c04d (diff) |
Add API::Helpers::Version and expose API root URL
This commits adds a new class that is supposed to represent Grape API
version, like `v3` or `v4`.
Diffstat (limited to 'spec/lib/api')
-rw-r--r-- | spec/lib/api/api_spec.rb | 17 | ||||
-rw-r--r-- | spec/lib/api/helpers/version_spec.rb | 26 |
2 files changed, 27 insertions, 16 deletions
diff --git a/spec/lib/api/api_spec.rb b/spec/lib/api/api_spec.rb index 31881551980..ceef0b41e59 100644 --- a/spec/lib/api/api_spec.rb +++ b/spec/lib/api/api_spec.rb @@ -15,22 +15,7 @@ describe API::API do 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 + expect(described_class.versions).to eq %w[v3 v4] end end end diff --git a/spec/lib/api/helpers/version_spec.rb b/spec/lib/api/helpers/version_spec.rb new file mode 100644 index 00000000000..63e7e1e6e95 --- /dev/null +++ b/spec/lib/api/helpers/version_spec.rb @@ -0,0 +1,26 @@ +require 'spec_helper' + +describe API::Helpers::Version do + describe '.new' do + it 'is possible to initialize it with existing API version' do + expect(described_class.new('v4').to_s).to eq 'v4' + end + + it 'raises an error when unsupported API version is provided' do + expect { described_class.new('v111') }.to raise_error ArgumentError + end + end + + describe '#root_path' do + it 'returns a root path of the API version' do + expect(described_class.new('v4').root_path).to eq '/api/v4' + end + end + + describe '#root_url' do + it 'returns an URL for a root path for the API version' do + expect(described_class.new('v4').root_url) + .to match %r{^http?://.*/api/v4$} + end + end +end |