Sha256: f0bd1593dc2c9e7daf010377b19b7618eb72b826277163d30f81f2afe6858d11
Contents?: true
Size: 920 Bytes
Versions: 7
Compression:
Stored size: 920 Bytes
Contents
RSpec.describe 'Schema with xor rules' do subject(:schema) do Dry::Validation.Schema do configure do def self.messages Messages.default.merge( en: { errors: { be_reasonable: 'you cannot eat cake and have cake!' } } ) end end required(:eat_cake).filled required(:have_cake).filled rule(:be_reasonable) do value(:eat_cake).eql?('yes!') ^ value(:have_cake).eql?('yes!') end end end describe '#messages' do it 'passes when only one option is selected' do messages = schema.(eat_cake: 'yes!', have_cake: 'no!').messages[:be_reasonable] expect(messages).to be(nil) end it 'fails when both options are selected' do messages = schema.(eat_cake: 'yes!', have_cake: 'yes!').messages[:be_reasonable] expect(messages).to eql(['you cannot eat cake and have cake!']) end end end
Version data entries
7 entries across 7 versions & 1 rubygems