Skip to content

Commit

Permalink
Fixed validation of invalid params with mutual_exclusive inside hash
Browse files Browse the repository at this point in the history
  • Loading branch information
lasseebert committed Jun 3, 2015
1 parent 2ec51f7 commit 4088745
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -23,6 +23,7 @@
* [#1005](https://github.com/intridea/grape/pull/1005): Fixed the Grape::Middleware::Globals - [@urkle](https://github.com/urkle).
* [#1012](https://github.com/intridea/grape/pull/1012): Fixed `allow_blank: false` with a Boolean value of `false` - [@mfunaro](https://github.com/mfunaro).
* [#1023](https://github.com/intridea/grape/issues/1023): Fixes unexpected beahvior with `present` and an object that responds to `merge` but isn't a Hash - [@dblock](https://github.com/dblock).
* [#1017](https://github.com/intridea/grape/pull/1017): Fixed `undefined method stringify_keys` with nested mutual exclusive params - [@quickpay](https://github.com/quickpay).
* Your contribution here.

0.11.0 (2/23/2015)
Expand Down
1 change: 1 addition & 0 deletions lib/grape/validations/validators/multiple_params_base.rb
Expand Up @@ -15,6 +15,7 @@ def scope_requires_params
end

def keys_in_common(resource_params)
return [] unless resource_params.is_a?(Hash)
(all_keys & resource_params.stringify_keys.keys).map(&:to_s)
end

Expand Down
19 changes: 19 additions & 0 deletions spec/grape/validations_spec.rb
Expand Up @@ -1132,6 +1132,25 @@ module SharedParams
expect(last_response.status).to eq(400)
end
end

context 'mutually exclusive params inside Hash group' do
it 'invalidates if request param is invalid type' do
subject.params do
optional :wine, type: Hash do
optional :grape
optional :country
mutually_exclusive :grape, :country
end
end
subject.post '/mutually_exclusive' do
'mutually_exclusive works!'
end

post '/mutually_exclusive', wine: '2015 sauvignon'
expect(last_response.status).to eq(400)
expect(last_response.body).to eq 'wine is invalid'
end
end
end

context 'exactly one of' do
Expand Down

0 comments on commit 4088745

Please sign in to comment.