Skip to content
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

add spec for renamed parameter in given block #2462

Closed
Changes from all commits
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
26 changes: 26 additions & 0 deletions spec/grape/endpoint/declared_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -829,5 +829,31 @@
expect(JSON.parse(last_response.body)).to match({})
end
end

context 'with a renamed field inside `given` block nested in hashes' do
before do
subject.format :json
subject.params do
requires :a, type: Hash do
optional :c, type: String
given :c do
requires :b, type: Hash do
requires :input_field, as: :output_field
end
end
end
end
subject.post '/test' do
declared(params)
end
end

it 'renames parameter input_field to output_field' do
post '/test', { a: { b: { input_field: 'value' }, c: 'value2' } }

expect(JSON.parse(last_response.body)).to \
match('a' => { 'b' => { 'output_field' => 'value' }, 'c' => 'value2' })
end
end
end
end