Skip to content

Commit

Permalink
Merge pull request #2299 from ruby-grape/fix_shared_params_empty_args
Browse files Browse the repository at this point in the history
fix, do not use kwargs for empty args
  • Loading branch information
dblock authored Dec 30, 2022
2 parents 02fd374 + b51665d commit d1b8e86
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#### Fixes

* [#2299](https://github.com/ruby-grape/grape/pull/2299): Fix, do not use kwargs for empty args - [@dm1try](https://github.com/dm1try).
* Your contribution here.

### 1.7.0 (2022/12/20)
Expand Down
7 changes: 6 additions & 1 deletion lib/grape/dsl/parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ def use(*names)
params_block = named_params.fetch(name) do
raise "Params :#{name} not found!"
end
instance_exec(**options, &params_block)

if options.empty?
instance_exec(options, &params_block)
else
instance_exec(**options, &params_block)
end
end
end
alias use_scope use
Expand Down
23 changes: 23 additions & 0 deletions spec/grape/validations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1509,6 +1509,29 @@ def validate_param!(attr_name, params)
end
end

context 'with block and empty args' do
before do
subject.helpers do
params :shared_params do |empty_args|
optional :param, default: empty_args[:some]
end
end
subject.format :json
subject.params do
use :shared_params
end
subject.get '/shared_params' do
:ok
end
end

it 'works' do
get '/shared_params'

expect(last_response.status).to eq(200)
end
end

context 'all or none' do
context 'optional params' do
before do
Expand Down

0 comments on commit d1b8e86

Please sign in to comment.