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

Version Path
riveter-0.8.3 spec/riveter/booleaness_validator_spec.rb
riveter-0.8.2 spec/riveter/booleaness_validator_spec.rb
riveter-0.8.1 spec/riveter/booleaness_validator_spec.rb
riveter-0.8.0 spec/riveter/booleaness_validator_spec.rb
riveter-0.7.0 spec/riveter/booleaness_validator_spec.rb
riveter-0.6.0 spec/riveter/booleaness_validator_spec.rb
riveter-0.3.0 spec/riveter/booleaness_validator_spec.rb
riveter-0.2.1 spec/riveter/booleaness_validator_spec.rb
riveter-0.2.0 spec/riveter/booleaness_validator_spec.rb
riveter-0.1.1 spec/riveter/booleaness_validator_spec.rb
riveter-0.0.15 spec/riveter/booleaness_validator_spec.rb
riveter-0.0.14 spec/riveter/booleaness_validator_spec.rb
riveter-0.0.13 spec/riveter/booleaness_validator_spec.rb
riveter-0.0.12 spec/riveter/booleaness_validator_spec.rb
riveter-0.0.11 spec/riveter/booleaness_validator_spec.rb
riveter-0.0.10 spec/riveter/booleaness_validator_spec.rb
riveter-0.0.9 spec/riveter/booleaness_validator_spec.rb
riveter-0.0.8 spec/riveter/booleaness_validator_spec.rb
riveter-0.0.7 spec/riveter/booleaness_validator_spec.rb