Sha256: c3e38462790cd03d76921db4f3504d39660d00f78473e4c3b0e4912956f180ed

Contents?: true

Size: 1.77 KB

Versions: 19

Compression:

Stored size: 1.77 KB

Contents

require 'spec_helper'

describe Riveter::EmailValidator do
  subject { Riveter::EmailValidator }

  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_an_email')
        expect(record).to receive(:errors).and_return(errors)

        validator.validate(record)
      }

      it {
        validator = subject.new(:attributes => [:test])
        record = record_for('some@email.com')
        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/email_validator_spec.rb
riveter-0.8.2 spec/riveter/email_validator_spec.rb
riveter-0.8.1 spec/riveter/email_validator_spec.rb
riveter-0.8.0 spec/riveter/email_validator_spec.rb
riveter-0.7.0 spec/riveter/email_validator_spec.rb
riveter-0.6.0 spec/riveter/email_validator_spec.rb
riveter-0.3.0 spec/riveter/email_validator_spec.rb
riveter-0.2.1 spec/riveter/email_validator_spec.rb
riveter-0.2.0 spec/riveter/email_validator_spec.rb
riveter-0.1.1 spec/riveter/email_validator_spec.rb
riveter-0.0.15 spec/riveter/email_validator_spec.rb
riveter-0.0.14 spec/riveter/email_validator_spec.rb
riveter-0.0.13 spec/riveter/email_validator_spec.rb
riveter-0.0.12 spec/riveter/email_validator_spec.rb
riveter-0.0.11 spec/riveter/email_validator_spec.rb
riveter-0.0.10 spec/riveter/email_validator_spec.rb
riveter-0.0.9 spec/riveter/email_validator_spec.rb
riveter-0.0.8 spec/riveter/email_validator_spec.rb
riveter-0.0.7 spec/riveter/email_validator_spec.rb