spec/grape/validations_spec.rb in grape-0.11.0 vs spec/grape/validations_spec.rb in grape-0.12.0
- old
+ new
@@ -351,11 +351,11 @@
expect(subject.route_setting(:declared_params)).to eq([items: [:key]])
end
end
context 'group params with nested params which has a type' do
- let(:invalid_items){ { items: '' } }
+ let(:invalid_items) { { items: '' } }
before do
subject.params do
optional :items, type: Array do
optional :key1, type: String
@@ -1128,9 +1128,28 @@
'mutually_exclusive_group works!'
end
get '/mutually_exclusive_group', drink: { beer: 'true', juice: 'true', wine: 'true' }
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