From 5f91706e64aa7ca1141eac1620274ce20c6de33f Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 18 Feb 2013 17:14:34 +0100 Subject: [PATCH] Allow to pass version as Accept param --- lib/travis/api/app/helpers/accept.rb | 5 +++++ spec/unit/helpers/accept_spec.rb | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/travis/api/app/helpers/accept.rb b/lib/travis/api/app/helpers/accept.rb index d5dd97c1..a57dfa8e 100644 --- a/lib/travis/api/app/helpers/accept.rb +++ b/lib/travis/api/app/helpers/accept.rb @@ -24,6 +24,11 @@ class Travis::Api::App "#{type}/#{subtype}" end + def version + version = @version || params['version'] + version ? "v#{version}" : nil + end + def accepts?(mime_type) return true if self.mime_type == '*/*' diff --git a/spec/unit/helpers/accept_spec.rb b/spec/unit/helpers/accept_spec.rb index 1ce845c6..cd41d0d3 100644 --- a/spec/unit/helpers/accept_spec.rb +++ b/spec/unit/helpers/accept_spec.rb @@ -18,7 +18,7 @@ module Travis::Api::App::Helpers accept_entry.quality.should == 0.2 accept_entry.params.should == { 'level' => '1', 'foo' => 'bar' } accept_entry.mime_type.should == 'application/json' - accept_entry.version.should == '2' + accept_entry.version.should == 'v2' end it 'returns */* for empty accept header' do @@ -27,6 +27,23 @@ module Travis::Api::App::Helpers end describe Accept::Entry do + describe 'version' do + it 'can be passed as a vendor extension' do + entry = Accept::Entry.new('application/vnd.travis-ci.2+json') + entry.version.should == 'v2' + end + + it 'can be passed as a param' do + entry = Accept::Entry.new('application/json; version=2') + entry.version.should == 'v2' + end + + it 'has a higher priority when in vendor extension' do + entry = Accept::Entry.new('application/vnd.travis-ci.1+json; version=2') + entry.version.should == 'v1' + end + end + describe 'accepts?' do it 'accepts everything with */* type' do entry = Accept::Entry.new('*/*')