Use version from each of the accept headers, not only first one
This commit is contained in:
parent
5f91706e64
commit
5345ef818e
|
@ -25,13 +25,17 @@ class Travis::Api::App
|
|||
end
|
||||
|
||||
def builder
|
||||
@builder ||= Travis::Api.builder(resource, { :version => accept_version }.merge(options))
|
||||
@builder ||= Travis::Api.builder(resource, { :version => version }.merge(options))
|
||||
end
|
||||
|
||||
def accept_params
|
||||
(options[:accept].params || {}).symbolize_keys
|
||||
end
|
||||
|
||||
def version
|
||||
options[:accept].version || Travis::Api::App::Helpers::Accept::DEFAULT_VERSION
|
||||
end
|
||||
|
||||
def params
|
||||
(request.params || {}).merge(accept_params)
|
||||
end
|
||||
|
|
26
spec/integration/version_spec.rb
Normal file
26
spec/integration/version_spec.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'App' do
|
||||
before do
|
||||
add_endpoint '/foo' do
|
||||
get '/' do
|
||||
respond_with foo: 'bar'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it 'uses version from current accept header' do
|
||||
Travis::Api.expects(:builder).with { |r, options| options[:version] == 'v1' }
|
||||
|
||||
Travis::Api::App::Responders::Json.any_instance.stubs(:apply?).
|
||||
returns(false).then.returns(true)
|
||||
|
||||
response = get '/foo', {}, 'HTTP_ACCEPT' => 'application/json; version=2, application/json; version=1'
|
||||
response.content_type.should == 'application/json;charset=utf-8'
|
||||
end
|
||||
|
||||
it 'uses v1 by default' do
|
||||
Travis::Api.expects(:builder).with { |r, options| options[:version] == 'v1' }
|
||||
get '/foo', {}, 'HTTP_ACCEPT' => 'application/json'
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user