Skip to content

Corrected the endpoint parameter name generation. #2189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Corrected already existing, but now broken specs.
Signed-off-by: Hermann Mayer <hermann.mayer92@gmail.com>
  • Loading branch information
Jack12816 committed Sep 11, 2021
commit 0717b8a3346c9858f69f01a1d99eca7b4e86be3c
2 changes: 1 addition & 1 deletion lib/grape/dsl/inside_route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def declared_array(passed_params, options, declared_params, params_nested_path)
end

def declared_hash(passed_params, options, declared_params, params_nested_path)
renamed_params = route_setting(:renamed_params)
renamed_params = route_setting(:renamed_params) || {}

declared_params.each_with_object(passed_params.class.new) do |declared_param, memo|
if declared_param.is_a?(Hash)
Expand Down
2 changes: 1 addition & 1 deletion spec/grape/endpoint/declared_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ def app
end
end

fdescribe 'parameter renaming' do
describe 'parameter renaming' do
context 'with a deeply nested parameter structure' do
let(:params) do
{
Expand Down
21 changes: 16 additions & 5 deletions spec/grape/validations/params_scope_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def initialize(value)
get '/renaming-coerced', foo: ' there we go '

expect(last_response.status).to eq(200)
expect(last_response.body).to eq('there we go-')
expect(last_response.body).to eq('-there we go')
end

it do
Expand Down Expand Up @@ -185,7 +185,7 @@ def initialize(value)
subject.params do
optional :foo, as: :bar, default: 'before'
end
subject.get('/rename-before-default') { params[:bar] }
subject.get('/rename-before-default') { declared(params)[:bar] }
get '/rename-before-default'

expect(last_response.status).to eq(200)
Expand All @@ -196,7 +196,7 @@ def initialize(value)
subject.params do
optional :foo, default: 'after', as: :bar
end
subject.get('/rename-after-default') { params[:bar] }
subject.get('/rename-after-default') { declared(params)[:bar] }
get '/rename-after-default'

expect(last_response.status).to eq(200)
Expand Down Expand Up @@ -590,7 +590,7 @@ def initialize(value)
it 'allows renaming of dependent on parameter' do
subject.params do
optional :a, as: :b
given b: ->(val) { val == 'x' } do
given a: ->(val) { val == 'x' } do
requires :c
end
end
Expand All @@ -604,14 +604,25 @@ def initialize(value)
expect(last_response.status).to eq 200
end

it 'raises an error if the dependent parameter is not the renamed one' do
it 'does not raise if the dependent parameter is not the renamed one' do
expect do
subject.params do
optional :a, as: :b
given :a do
requires :c
end
end
end.not_to raise_error
end

it 'raises an error if the dependent parameter is the renamed one' do
expect do
subject.params do
optional :a, as: :b
given :b do
requires :c
end
end
end.to raise_error(Grape::Exceptions::UnknownParameter)
end

Expand Down