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

fix(#2236): Stripping the internals of Grape::Endpoint when NoMethodError is raised #2368

Merged
merged 3 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -12,6 +12,7 @@

* [#2364](https://github.com/ruby-grape/grape/pull/2364): Add missing requires - [@ericproulx](https://github.com/ericproulx).
* [#2366](https://github.com/ruby-grape/grape/pull/2366): Default quality to 1.0 in the `Accept` header when omitted - [@hiddewie](https://github.com/hiddewie).
* [#2368](https://github.com/ruby-grape/grape/pull/2368): Stripping the internals of `Grape::Endpoint` when `NoMethodError` is raised - [@jcagarcia](https://github.com/jcagarcia).
* Your contribution here.

### 1.8.0 (2023/08/30)
Expand Down
4 changes: 4 additions & 0 deletions lib/grape/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -403,5 +403,9 @@ def options?
options[:options_route_enabled] &&
env[Grape::Http::Headers::REQUEST_METHOD] == Grape::Http::Headers::OPTIONS
end

def method_missing(name, *args)
raise NoMethodError.new("undefined method `#{name}` for #{self.class}")
jcagarcia marked this conversation as resolved.
Show resolved Hide resolved
end
end
end
11 changes: 11 additions & 0 deletions spec/grape/endpoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,17 @@ def app
end
end

describe '#method_missing' do
it 'raises NoMethodError but stripping the internals of the Grape::Endpoint class' do
subject.get('/hey') do
undefined_helper
end
expect {
get '/hey'
}.to raise_error(NoMethodError, /^undefined method `undefined_helper` for #<Class:0x[0-9a-fA-F]+>$/)
end
end

it 'does not persist params between calls' do
subject.post('/new') do
params[:text]
Expand Down