Skip to content

Commit 7d73ca6

Browse files
authored
Merge pull request #2109 from tlconnor/fixArrayParams
Fix bug with handling array params.
2 parents f1aaab6 + 028c10e commit 7d73ca6

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lib/grape/dsl/inside_route.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ def declared_hash(passed_params, options, declared_params, params_nested_path)
7575

7676
params_nested_path_dup = params_nested_path.dup
7777
params_nested_path_dup << declared_param.to_s
78-
79-
memo[memo_key] = handle_passed_param(params_nested_path_dup) do
78+
memo[memo_key] = passed_param || handle_passed_param(params_nested_path_dup) do
8079
passed_param
8180
end
8281
end

spec/grape/endpoint/declared_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,20 @@ def app
135135
expect(JSON.parse(last_response.body)['nested'].keys.size).to eq 9
136136
end
137137

138+
it 'builds arrays correctly' do
139+
subject.params do
140+
requires :first
141+
optional :second, type: Array
142+
end
143+
subject.post('/declared') { declared(params) }
144+
145+
post '/declared', first: 'present', second: ['present']
146+
expect(last_response.status).to eq(201)
147+
148+
body = JSON.parse(last_response.body)
149+
expect(body['second']).to eq(['present'])
150+
end
151+
138152
it 'builds nested params when given array' do
139153
subject.get '/dummy' do
140154
end

0 commit comments

Comments
 (0)