Skip to content

Commit

Permalink
Merge pull request #1903 from bikolya/fix-nested-params-renaming
Browse files Browse the repository at this point in the history
Fix Hash params renaming
  • Loading branch information
dblock committed Aug 30, 2019
2 parents aadbd0d + c57d97c commit 5476b27
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* [#1893](https://github.com/ruby-grape/grape/pull/1893): Allows `Grape::API` to behave like a Rack::app in some instances where it was misbehaving - [@myxoh](https://github.com/myxoh).
* [#1898](https://github.com/ruby-grape/grape/pull/1898): Refactor `ValidatorFactory` to improve memory allocation - [@Bhacaz](https://github.com/Bhacaz).
* [#1900](https://github.com/ruby-grape/grape/pull/1900): Define boolean for `Grape::Api::Instance` - [@Bhacaz](https://github.com/Bhacaz).
* [#1903](https://github.com/ruby-grape/grape/pull/1903): Allow nested params renaming (Hash/Array) - [@bikolya](https://github.com/bikolya).

### 1.2.4 (2019/06/13)

Expand Down
2 changes: 1 addition & 1 deletion lib/grape/validations/params_scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def new_scope(attrs, optional = false, &block)

self.class.new(
api: @api,
element: attrs.first,
element: attrs[1][:as] || attrs.first,
parent: self,
optional: optional,
type: type || Array,
Expand Down
13 changes: 13 additions & 0 deletions spec/grape/validations/params_scope_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,19 @@ def initialize(value)

expect(last_response.status).to eq(200)
end

it do
subject.params do
requires :foo, as: :baz, type: Hash do
requires :bar, as: :qux
end
end
subject.get('/nested-renaming') { declared(params).to_json }
get '/nested-renaming', foo: { bar: 'any' }

expect(last_response.status).to eq(200)
expect(last_response.body).to eq('{"baz":{"qux":"any"}}')
end
end

context 'array without coerce type explicitly given' do
Expand Down

0 comments on commit 5476b27

Please sign in to comment.