Skip to content

Commit

Permalink
Merge pull request #1017 from QuickPay/mutual_exclusive_inside_hash
Browse files Browse the repository at this point in the history
Fixed validation of invalid params with mutual_exclusive inside hash
  • Loading branch information
dblock committed Jun 4, 2015
2 parents 2ec51f7 + 4088745 commit 877e089
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 877e089

Please sign in to comment.