diff --git a/UPGRADING.md b/UPGRADING.md index 894389c229..f8cdb93b37 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -53,7 +53,7 @@ end #### Recognizing Path -Due to the changes done in [#2379](https://github.com/ruby-grape/grape/pull/2379), Grape now takes in mind the types of the configured `route_params` in order to determine the endpoint that matches with the performed request. +Grape now considers the types of the configured `route_params` in order to determine the endpoint that matches with the performed request. So taking into account this `Grape::API` class @@ -77,14 +77,14 @@ class Books < Grape::API end ``` -This was the behavior before the changes: +Before: ```ruby API.recognize_path '/books/1' # => /books/:id API.recognize_path '/books/share' # => /books/:id API.recognize_path '/books/other' # => /books/:id ``` -And this is the behavior now: +After: ```ruby API.recognize_path '/books/1' # => /books/:id API.recognize_path '/books/share' # => /books/share @@ -93,6 +93,8 @@ API.recognize_path '/books/other' # => nil This implies that before this changes, when you performed `/books/other` and it matched with the `/books/:id` endpoint, you get a `400 Bad Request` response because the type of the provided `:id` param was not an `Integer`. However, after upgrading to version `2.1.0` you will get a `404 Not Found` response, because there is not a defined endpoint that matches with `/books/other`. +See [#2379](https://github.com/ruby-grape/grape/pull/2379) for more information. + ### Upgrading to >= 2.0.0 #### Headers diff --git a/spec/grape/api/recognize_path_spec.rb b/spec/grape/api/recognize_path_spec.rb index 5e9db2839d..04b0b48b8a 100644 --- a/spec/grape/api/recognize_path_spec.rb +++ b/spec/grape/api/recognize_path_spec.rb @@ -47,41 +47,29 @@ end end - context 'when the parameter does not match with the specified type' do - it 'recognizes the static route' do - actual = subject.recognize_path('/books/share').routes[0].origin - expect(actual).to eq('/books/share') - end + it 'recognizes the static route when the parameter does not match with the specified type' do + actual = subject.recognize_path('/books/share').routes[0].origin + expect(actual).to eq('/books/share') + end - context 'when there is not other endpoint that matches with the requested path' do - it 'does not recognize any endpoint' do - actual = subject.recognize_path('/books/other') - expect(actual).to be_nil - end - end + it 'does not recognize any endpoint when there is not other endpoint that matches with the requested path' do + actual = subject.recognize_path('/books/other') + expect(actual).to be_nil end - context 'when the parameter matches with the specified type' do - it 'recognizes the parametrized route' do - actual = subject.recognize_path('/books/1').routes[0].origin - expect(actual).to eq('/books/:id') - end + it 'recognizes the parametrized route when the parameter matches with the specified type' do + actual = subject.recognize_path('/books/1').routes[0].origin + expect(actual).to eq('/books/:id') end - context 'when requesting nested paths' do - context 'when the parameter does not match with the specified type' do - it 'recognizes the static route' do - actual = subject.recognize_path('/books/1/loans/print').routes[0].origin - expect(actual).to eq('/books/:id/loans/print') - end - end + it 'recognizes the static nested route when the parameter does not match with the specified type' do + actual = subject.recognize_path('/books/1/loans/print').routes[0].origin + expect(actual).to eq('/books/:id/loans/print') + end - context 'when the parameter matches with the specified type' do - it 'recognizes the parametrized route' do - actual = subject.recognize_path('/books/1/loans/33').routes[0].origin - expect(actual).to eq('/books/:id/loans/:loan_id') - end - end + it 'recognizes the nested parametrized route when the parameter matches with the specified type' do + actual = subject.recognize_path('/books/1/loans/33').routes[0].origin + expect(actual).to eq('/books/:id/loans/:loan_id') end end end