From 0ac34494fb59de4143ff4d8f5b65a40fa73b59d3 Mon Sep 17 00:00:00 2001 From: Boris Drovnin Date: Tue, 25 Jun 2024 20:42:53 +0300 Subject: [PATCH] add spec for renamed parameter in given block --- spec/grape/endpoint/declared_spec.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/spec/grape/endpoint/declared_spec.rb b/spec/grape/endpoint/declared_spec.rb index dcf2fe9d62..58583bc86a 100644 --- a/spec/grape/endpoint/declared_spec.rb +++ b/spec/grape/endpoint/declared_spec.rb @@ -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