Skip to content

Commit ed88a19

Browse files
author
Michael Bleigh
committed
Adds api.endpoint when called to help introspection and testability.
1 parent 638112f commit ed88a19

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/grape/endpoint.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def call(env)
8383
end
8484

8585
def call!(env)
86+
env['api.endpoint'] = self
8687
if options[:app]
8788
options[:app].call(env)
8889
else

spec/grape/endpoint_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ def app; subject end
1414
end
1515
end
1616

17+
it 'should set itself in the env upon call' do
18+
subject.get('/'){ "Hello world." }
19+
get '/'
20+
last_request.env['api.endpoint'].should be_kind_of(Grape::Endpoint)
21+
end
22+
1723
describe '#status' do
1824
it 'should be callable from within a block' do
1925
subject.get('/home') do

0 commit comments

Comments
 (0)