Skip to content

Commit

Permalink
Merge 1c6eafd into 02fd374
Browse files Browse the repository at this point in the history
  • Loading branch information
dm1try committed Dec 29, 2022
2 parents 02fd374 + 1c6eafd commit 22ec9cb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
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 22ec9cb

Please sign in to comment.