Sha256: d1a2fa9885d22d5a99b60919596f5d57a4ae3dea5716f87ef416de0bea036059
Contents?: true
Size: 1.95 KB
Versions: 19
Compression:
Stored size: 1.95 KB
Contents
require 'spec_helper' describe Riveter::BooleanessValidator do subject { Riveter::BooleanessValidator } describe "#validate_each" do def record_for(value) record = double() allow(record).to receive(:read_attribute_for_validation) { value } record end def errors errors = double allow(errors).to receive(:add) errors end describe "with defaults" do it { validator = subject.new(:attributes => [:test]) record = record_for('not_a_boolean') expect(record).to receive(:errors).and_return(errors) validator.validate(record) } it { validator = subject.new(:attributes => [:test]) record = record_for(true) expect(record).to_not receive(:errors) validator.validate(record) } it { validator = subject.new(:attributes => [:test]) record = record_for(false) expect(record).to_not receive(:errors) validator.validate(record) } end describe "with allow_nil" do it { validator = subject.new(:attributes => [:test], :allow_nil => false) record = record_for(nil) expect(record).to receive(:errors).and_return(errors) validator.validate(record) } it { validator = subject.new(:attributes => [:test], :allow_nil => true) record = record_for(nil) expect(record).to_not receive(:errors) validator.validate(record) } end describe "with allow_blank" do it { validator = subject.new(:attributes => [:test], :allow_blank => false) record = record_for('') expect(record).to receive(:errors).and_return(errors) validator.validate(record) } it { validator = subject.new(:attributes => [:test], :allow_blank => true) record = record_for('') expect(record).to_not receive(:errors) validator.validate(record) } end end end
Version data entries
19 entries across 19 versions & 1 rubygems