Sha256: 6518356c149d8c3aac5080acf54246df634c00bf1292e13d48ecc0a68127b6d3
Contents?: true
Size: 1.76 KB
Versions: 3
Compression:
Stored size: 1.76 KB
Contents
require 'spec_helper' describe Grape::Validations::MutualExclusionValidator do describe '#validate!' do let(:scope) do Struct.new(:opts) do def params(arg); end end end let(:mutually_exclusive_params) { [:beer, :wine, :grapefruit] } let(:validator) { described_class.new(mutually_exclusive_params, {}, false, scope.new) } context 'when all mutually exclusive params are present' do let(:params) { { beer: true, wine: true, grapefruit: true } } it 'raises a validation exception' do expect { validator.validate! params }.to raise_error(Grape::Exceptions::Validation) end context 'mixed with other params' do let(:mixed_params) { params.merge!(other: true, andanother: true) } it 'still raises a validation exception' do expect { validator.validate! mixed_params }.to raise_error(Grape::Exceptions::Validation) end end end context 'when a subset of mutually exclusive params are present' do let(:params) { { beer: true, grapefruit: true } } it 'raises a validation exception' do expect { validator.validate! params }.to raise_error(Grape::Exceptions::Validation) end end context 'when params keys come as strings' do let(:params) { { 'beer' => true, 'grapefruit' => true } } it 'raises a validation exception' do expect { validator.validate! params }.to raise_error(Grape::Exceptions::Validation) end end context 'when no mutually exclusive params are present' do let(:params) { { beer: true, somethingelse: true } } it 'params' do expect(validator.validate!(params)).to eql params end end end end
Version data entries
3 entries across 3 versions & 2 rubygems