Skip to content

Commit 48f70cc

Browse files
authored
Merge pull request #2628 from giorni/fix-helper-inheritance
Fix grape mounted helpers inheritance
2 parents 5fa9fb1 + f952271 commit 48f70cc

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#### Fixes
1010

11+
* [#2628](https://github.com/ruby-grape/grape/pull/2628): Fix helpers inheritance - [@giorni](https://github.com/giorni).
1112
* Your contribution here.
1213

1314
### 3.0.0 (2025-11-15)

lib/grape/endpoint.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ def initialize(new_settings, options = {}, &block)
7575
@stream = nil
7676
@body = nil
7777
@source = block
78-
@helpers = build_helpers
7978
end
8079

8180
# Update our settings from a given set of stackable parameters. Used when
@@ -258,6 +257,7 @@ def lazy_initialize!
258257
return true if @lazy_initialized
259258

260259
@app = options[:app] || build_stack
260+
@helpers = build_helpers
261261
@lazy_initialized = true
262262
end
263263
end
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# frozen_string_literal: true
2+
3+
describe Grape::API do
4+
context 'when mounting a child API that inherits helpers from parent API' do
5+
let(:child_api) do
6+
Class.new(Grape::API) do
7+
get '/test' do
8+
parent_helper
9+
end
10+
end
11+
end
12+
13+
let(:parent_api) do
14+
context = self
15+
Class.new(Grape::API) do
16+
helpers do
17+
def parent_helper
18+
'parent helper value'
19+
end
20+
end
21+
22+
mount context.child_api
23+
end
24+
end
25+
26+
def app
27+
parent_api
28+
end
29+
30+
it 'inherits helpers from parent API to mounted child API' do
31+
get '/test'
32+
expect(last_response.status).to eq(200)
33+
expect(last_response.body).to eq('parent helper value')
34+
end
35+
end
36+
end

0 commit comments

Comments
 (0)