Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #116 from jwkoelewijn/frontier-vendoring

Frontier vendoring
  • Loading branch information...
commit 5a3bc1eac0a4ef723aed3c7382686ad1c351edcc 2 parents f42b394 + 9447781
@jch jch authored
View
5 lib/grape/middleware/versioner/header.rb
@@ -35,7 +35,10 @@ def before
env['api.subtype'] = subtype
subtype.scan(/vnd\.(.+)?-(.+)?\+(.*)?/) do |vendor, version, format|
- if options[:versions] && !options[:versions].include?(version)
+ is_vendored = options[:version_options] && options[:version_options][:vendor]
+ is_vendored_match = is_vendored ? options[:version_options][:vendor] == vendor : true
+
+ if (options[:versions] && !options[:versions].include?(version)) || !is_vendored_match
throw :error, :status => 404, :headers => {'X-Cascade' => 'pass'}, :message => "404 API Version Not Found"
end
View
20 spec/grape/middleware/versioner/header_spec.rb
@@ -80,6 +80,26 @@
end
end
+ context 'vendors' do
+ before do
+ @options = {
+ :version => ['v1'],
+ :version_options => {:using => :header, :vendor => 'vendor'}
+ }
+ end
+
+ it 'should match with correct vendor' do
+ status = subject.call('HTTP_ACCEPT' => accept).first
+ status.should == 200
+ end
+
+ it 'should not match with an incorrect vendor' do
+ expect {
+ env = subject.call('HTTP_ACCEPT' => 'application/vnd.othervendor-v1+json').last
+ }.to throw_symbol(:error, :status => 404, :headers => {'X-Cascade' => 'pass'}, :message => "404 API Version Not Found")
+ end
+ end
+
context 'no matched version' do
before do
@options = {
Please sign in to comment.
Something went wrong with that request. Please try again.