Skip to content

Commit e7f771e

Browse files
authored
fixes configuration inside namespaced params scope (#2152)
1 parent 56db533 commit e7f771e

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* [#2137](https://github.com/ruby-grape/grape/pull/2137): Fix typos - [@johnny-miyake](https://github.com/johnny-miyake).
1414
* [#2131](https://github.com/ruby-grape/grape/pull/2131): Fix Ruby 2.7 keyword deprecation warning in validators/coerce - [@K0H205](https://github.com/K0H205).
1515
* [#2132](https://github.com/ruby-grape/grape/pull/2132): Use #ruby2_keywords for correct delegation on Ruby <= 2.6, 2.7 and 3 - [@eregon](https://github.com/eregon).
16+
* [#2152](https://github.com/ruby-grape/grape/pull/2152): Fix configuration method inside namespaced params - [@fsainz](https://github.com/fsainz).
1617

1718
### 1.5.1 (2020/11/15)
1819

lib/grape/validations/params_scope.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def initialize(opts, &block)
3939
end
4040

4141
def configuration
42-
@api.configuration.evaluate
42+
@api.configuration.respond_to?(:evaluate) ? @api.configuration.evaluate : @api.configuration
4343
end
4444

4545
# @return [Boolean] whether or not this entire scope needs to be

spec/grape/api_remount_spec.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,19 +340,24 @@ def app
340340
context 'when the configuration is read within a namespace' do
341341
before do
342342
a_remounted_api.namespace 'api' do
343+
params do
344+
requires configuration[:required_param]
345+
end
343346
get "/#{configuration[:path]}" do
344347
'10 votes'
345348
end
346349
end
347-
root_api.mount a_remounted_api, with: { path: 'votes' }
348-
root_api.mount a_remounted_api, with: { path: 'scores' }
350+
root_api.mount a_remounted_api, with: { path: 'votes', required_param: 'param_key' }
351+
root_api.mount a_remounted_api, with: { path: 'scores', required_param: 'param_key' }
349352
end
350353

351354
it 'will use the dynamic configuration on all routes' do
352-
get 'api/votes'
355+
get 'api/votes', param_key: 'a'
353356
expect(last_response.body).to eql '10 votes'
354-
get 'api/scores'
357+
get 'api/scores', param_key: 'a'
355358
expect(last_response.body).to eql '10 votes'
359+
get 'api/votes'
360+
expect(last_response.status).to eq 400
356361
end
357362
end
358363

0 commit comments

Comments
 (0)