Sha256: d8c2278ffbfebe50fc4a21c752069cc65d8c8edb5cfe7d6f5668ca108f73f389

Contents?: true

Size: 1.85 KB

Versions: 10

Compression:

Stored size: 1.85 KB

Contents

require 'factories/profiles.rb'

describe EmailFormatValidator do

  let(:subject) { EmailFormatValidator }

  let( :attribute ) { :email }
  let (:object) { Profile.new }

  invalid_addresses = %w[user@fail,com user_at.com user_fail.com user@ @fail.com ryan`1`@system88.com]
  valid_addresses = %w[user@pass.com user_user@pass.com user.user@pass.com ryan+stage@systme88.com]


  context 'Wrong email format' do

    context 'No message is sent on the options' do
      it 'it returns error message expecified on the validator' do
        n  = subject.new( { attributes: attribute } )
        invalid_addresses.each do |invalid_address|
          expect(n.validate_each(object, attribute, invalid_address)).to include('enter a valid email address (e.g. name@example.com)')
        end
      end
    end

    context 'Message is sent on the options' do
      it 'it returns error message expecified on the options' do
        n  = subject.new( { message: 'Test error message', attributes: :postal_code } )
        invalid_addresses.each do |invalid_address|
          expect(n.validate_each(object, attribute, invalid_address)).to include('Test error message')
        end
      end
    end

  end

  context 'Correct email format' do

    context 'No message is sent on the options' do
      it 'it does not return error message' do
        n  = subject.new( { attributes: attribute } )
        valid_addresses.each do |valid_address|
          expect(n.validate_each(object, attribute, valid_address)).to equal(nil)
        end
      end
    end

    context 'Message is sent on the options' do
      it 'it does not return error message' do
        n  = subject.new( { message: 'Test error message', attributes: attribute } )
        valid_addresses.each do |valid_address|
          expect(n.validate_each(object, attribute, valid_address)).to equal(nil)
        end
      end
    end

  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ama_validators-0.0.13 spec/email_format_validator_spec.rb
ama_validators-0.0.12 spec/email_format_validator_spec.rb
ama_validators-0.0.11 spec/email_format_validator_spec.rb
ama_validators-0.0.10 spec/email_format_validator_spec.rb
ama_validators-0.0.9 spec/email_format_validator_spec.rb
ama_validators-0.0.8 spec/email_format_validator_spec.rb
ama_validators-0.0.7 spec/email_format_validator_spec.rb
ama_validators-0.0.6 spec/email_format_validator_spec.rb
ama_validators-0.0.5 spec/email_format_validator_spec.rb
ama_validators-0.0.4 spec/email_format_validator_spec.rb