Skip to content

Commit

Permalink
fix(ruby-grape#2350): Updating wording and passing rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
jcagarcia committed Nov 25, 2023
1 parent c8adb79 commit 1a54d4f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 32 deletions.
8 changes: 5 additions & 3 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down
46 changes: 17 additions & 29 deletions spec/grape/api/recognize_path_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1a54d4f

Please sign in to comment.