-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathnested_helpers_spec.rb
52 lines (44 loc) · 997 Bytes
/
nested_helpers_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# frozen_string_literal: true
describe Grape::API::Helpers do
let(:helper_methods) do
Module.new do
extend Grape::API::Helpers
def current_user
@current_user ||= params[:current_user]
end
end
end
let(:nested) do
context = self
Class.new(Grape::API) do
resource :level1 do
helpers context.helper_methods
get do
current_user
end
resource :level2 do
get do
current_user
end
end
end
end
end
let(:main) do
context = self
Class.new(Grape::API) do
mount context.nested
end
end
def app
main
end
it 'can access helpers from a mounted resource' do
get '/level1', current_user: 'hello'
expect(last_response.body).to eq('hello')
end
it 'can access helpers from a mounted resource in a nested resource' do
get '/level1/level2', current_user: 'world'
expect(last_response.body).to eq('world')
end
end