|
89 | 89 | expect(exception).to be_a(Grape::Exceptions::InvalidAcceptHeader)
|
90 | 90 | expect(exception.headers).to eql('X-Cascade' => 'pass')
|
91 | 91 | expect(exception.status).to eql 406
|
92 |
| - expect(exception.message).to include 'API vendor or version not found' |
| 92 | + expect(exception.message).to include 'API vendor not found' |
93 | 93 | end
|
94 | 94 | end
|
95 | 95 |
|
|
116 | 116 | expect(exception).to be_a(Grape::Exceptions::InvalidAcceptHeader)
|
117 | 117 | expect(exception.headers).to eql('X-Cascade' => 'pass')
|
118 | 118 | expect(exception.status).to eql 406
|
119 |
| - expect(exception.message).to include('API vendor or version not found') |
| 119 | + expect(exception.message).to include('API vendor not found') |
120 | 120 | end
|
121 | 121 | end
|
122 | 122 | end
|
|
141 | 141 |
|
142 | 142 | it 'fails with 406 Not Acceptable if version is invalid' do
|
143 | 143 | expect { subject.call('HTTP_ACCEPT' => 'application/vnd.vendor-v2+json').last }.to raise_exception do |exception|
|
144 |
| - expect(exception).to be_a(Grape::Exceptions::InvalidAcceptHeader) |
| 144 | + expect(exception).to be_a(Grape::Exceptions::InvalidVersionHeader) |
145 | 145 | expect(exception.headers).to eql('X-Cascade' => 'pass')
|
146 | 146 | expect(exception.status).to eql 406
|
147 |
| - expect(exception.message).to include('API vendor or version not found') |
| 147 | + expect(exception.message).to include('API version not found') |
148 | 148 | end
|
149 | 149 | end
|
150 | 150 | end
|
|
244 | 244 |
|
245 | 245 | it 'fails with another version' do
|
246 | 246 | expect { subject.call('HTTP_ACCEPT' => 'application/vnd.vendor-v3+json') }.to raise_exception do |exception|
|
247 |
| - expect(exception).to be_a(Grape::Exceptions::InvalidAcceptHeader) |
| 247 | + expect(exception).to be_a(Grape::Exceptions::InvalidVersionHeader) |
248 | 248 | expect(exception.headers).to eql('X-Cascade' => 'pass')
|
249 | 249 | expect(exception.status).to eql 406
|
250 |
| - expect(exception.message).to include('API vendor or version not found') |
| 250 | + expect(exception.message).to include('API version not found') |
| 251 | + end |
| 252 | + end |
| 253 | + end |
| 254 | + |
| 255 | + context 'when there are multiple versions specified with rescue_from :all' do |
| 256 | + subject { |
| 257 | + Class.new(Grape::API) do |
| 258 | + rescue_from :all |
| 259 | + end |
| 260 | + } |
| 261 | + |
| 262 | + let(:v1_app) { |
| 263 | + Class.new(Grape::API) do |
| 264 | + version 'v1', using: :header, vendor: 'test' |
| 265 | + resources :users do |
| 266 | + get :hello do |
| 267 | + 'one' |
| 268 | + end |
| 269 | + end |
| 270 | + end |
| 271 | + } |
| 272 | + |
| 273 | + let(:v2_app) { |
| 274 | + Class.new(Grape::API) do |
| 275 | + version 'v2', using: :header, vendor: 'test' |
| 276 | + resources :users do |
| 277 | + get :hello do |
| 278 | + 'two' |
| 279 | + end |
| 280 | + end |
| 281 | + end |
| 282 | + } |
| 283 | + |
| 284 | + def app |
| 285 | + subject.mount v1_app |
| 286 | + subject.mount v2_app |
| 287 | + subject |
| 288 | + end |
| 289 | + |
| 290 | + context 'with header versioned endpoints and a rescue_all block defined' do |
| 291 | + it 'responds correctly to a v1 request' do |
| 292 | + versioned_get '/users/hello', 'v1', using: :header, vendor: 'test' |
| 293 | + expect(last_response.body).to eq('one') |
| 294 | + expect(last_response.body).not_to include('API vendor or version not found') |
| 295 | + end |
| 296 | + |
| 297 | + it 'responds correctly to a v2 request' do |
| 298 | + versioned_get '/users/hello', 'v2', using: :header, vendor: 'test' |
| 299 | + expect(last_response.body).to eq('two') |
| 300 | + expect(last_response.body).not_to include('API vendor or version not found') |
251 | 301 | end
|
252 | 302 | end
|
253 | 303 | end
|
|
0 commit comments