File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
lib/grape/middleware/versioner
spec/grape/middleware/versioner Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,10 @@ def before
3535 env [ 'api.subtype' ] = subtype
3636
3737 subtype . scan ( /vnd\. (.+)?-(.+)?\+ (.*)?/ ) do |vendor , version , format |
38- if options [ :versions ] && !options [ :versions ] . include? ( version )
38+ is_vendored = options [ :version_options ] && options [ :version_options ] [ :vendor ]
39+ is_vendored_match = is_vendored ? options [ :version_options ] [ :vendor ] == vendor : true
40+
41+ if ( options [ :versions ] && !options [ :versions ] . include? ( version ) ) || !is_vendored_match
3942 throw :error , :status => 404 , :headers => { 'X-Cascade' => 'pass' } , :message => "404 API Version Not Found"
4043 end
4144
Original file line number Diff line number Diff line change 8080 end
8181 end
8282
83+ context 'vendors' do
84+ before do
85+ @options = {
86+ :version => [ 'v1' ] ,
87+ :version_options => { :using => :header , :vendor => 'vendor' }
88+ }
89+ end
90+
91+ it 'should match with correct vendor' do
92+ status = subject . call ( 'HTTP_ACCEPT' => accept ) . first
93+ status . should == 200
94+ end
95+
96+ it 'should not match with an incorrect vendor' do
97+ expect {
98+ env = subject . call ( 'HTTP_ACCEPT' => 'application/vnd.othervendor-v1+json' ) . last
99+ } . to throw_symbol ( :error , :status => 404 , :headers => { 'X-Cascade' => 'pass' } , :message => "404 API Version Not Found" )
100+ end
101+ end
102+
83103 context 'no matched version' do
84104 before do
85105 @options = {
You can’t perform that action at this time.
0 commit comments