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

Fix Hash params renaming #1903

Merged
merged 1 commit into from
Aug 30, 2019
Merged
Show file tree
Hide file tree
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
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