Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed undefined method reject for nil:NilClass error on an undefined route. #127

Merged
merged 1 commit into from
Jul 22, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Added `GrapeEntity::VERSION` - [@dblock](https://github.com/dblock).
* Added Rubocop, Ruby-style linter - [@dblock](https://github.com/dblock).
* [#126](https://github.com/tim-vandecasteele/grape-swagger/pull/126): Rewritten demo in the `test` folder with CORS enabled - [@dblock](https://github.com/dblock).
* [#127](https://github.com/tim-vandecasteele/grape-swagger/pull/127): Fixed `undefined method 'reject' for nil:NilClass` error for an invalid route, now returning 404 Not Found - [@dblock](https://github.com/dblock).
* Your Contribution Here

### 0.7.2 (February 6, 2014)
Expand Down
3 changes: 3 additions & 0 deletions lib/grape-swagger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,14 @@ def self.setup(options)

models = []
routes = target_class.combined_routes[params[:name]]
error!('Not Found', 404) unless routes

ops = routes.reject(&:route_hidden).group_by do |route|
parse_path(route.route_path, api_version)
end

error!('Not Found', 404) unless ops.any?

apis = []

ops.each do |path, op_routes|
Expand Down
25 changes: 25 additions & 0 deletions spec/non_default_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -634,4 +634,29 @@ def app
expect(ret['apis'][0]['operations'][0]['nickname']).to eq 'getSomething'
end
end

context 'invalid name' do
subject do
Class.new(Grape::API) do
get 'hidden', hidden: true
add_swagger_documentation
end
end

def app
subject
end

it 'returns a 404 for an non-existent route' do
get '/swagger_doc/invalid.json'
expect(last_response.status).to eq 404
expect(JSON.parse(last_response.body)).to eq('error' => 'Not Found')
end

it 'returns a 404 for a hidden route' do
get '/swagger_doc/hidden.json'
expect(last_response.status).to eq 404
expect(JSON.parse(last_response.body)).to eq('error' => 'Not Found')
end
end
end