Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -13,6 +13,7 @@
* [#2480](https://github.com/ruby-grape/grape/pull/2480): Fix rescue_from ValidationErrors exception - [@numbata](https://github.com/numbata).
* [#2464](https://github.com/ruby-grape/grape/pull/2464): The `length` validator only takes effect for parameters with types that support `#length` method - [@OuYangJinTing](https://github.com/OuYangJinTing).
* [#2485](https://github.com/ruby-grape/grape/pull/2485): Add `is:` param to length validator - [@dakad](https://github.com/dakad).
* [#2492](https://github.com/ruby-grape/grape/pull/2492): Fix Grape::Endpoint's inspect method - [@ericproulx](https://github.com/ericproulx).
* Your contribution here.

### 2.1.3 (2024-07-13)
Expand Down
13 changes: 9 additions & 4 deletions lib/grape/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,15 @@ def equals?(endpoint)
(options == endpoint.options) && (inheritable_setting.to_hash == endpoint.inheritable_setting.to_hash)
end

# the purpose of this override is solely for stripping internals when an error occurs while calling
# an endpoint through an api. See #https://github.com/ruby-grape/grape/issues/2398
# Otherwise, it calls super
def inspect
return super unless env

"#{self.class} in `#{route.origin}' endpoint"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this meant to be quoted differently?

Suggested change
"#{self.class} in `#{route.origin}' endpoint"
"#{self.class} in '#{route.origin}' endpoint"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://bugs.ruby-lang.org/issues/16495
Looks like something cultural

end

protected

def run
Expand Down Expand Up @@ -403,9 +412,5 @@ def options?
options[:options_route_enabled] &&
env[Rack::REQUEST_METHOD] == Rack::OPTIONS
end

def inspect
"#{self.class} in `#{route.origin}' endpoint"
end
end
end
20 changes: 20 additions & 0 deletions spec/grape/endpoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1088,4 +1088,24 @@ def memoized
)
end
end

describe '#inspect' do
subject { described_class.new(settings, options).inspect }

let(:options) do
{
method: :path,
path: '/path',
app: {},
route_options: { anchor: false },
forward_match: true,
for: Class.new
}
end
let(:settings) { Grape::Util::InheritableSetting.new }

it 'does not raise an error' do
expect { subject }.not_to raise_error
end
end
end