Sha256: 97ce70646457dd646f4ea174944083d75e764aa4bb1ac0ad9b2394155c2386e0

Contents?: true

Size: 1.94 KB

Versions: 10

Compression:

Stored size: 1.94 KB

Contents

require 'factories/profiles.rb'

describe PhoneNumberFormatValidator do

  let(:subject) { PhoneNumberFormatValidator }

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

  invalid_phone_numbers = %w[123 780123456 1234456 666 mynumber 780myphone]
  valid_phone_numbers = %w[587-555-5555 5875555555 1234567890 17809172969 (780)9172969 7809172969 +17809172969 +1(780)9172969]

  context 'Wrong phone number 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_phone_numbers.each do |invalid_phone_number|
          expect(n.validate_each(object, attribute, invalid_phone_number)).to include('enter a valid 10-digit number (e.g. 587-555-5555)')
        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: attribute } )
        invalid_phone_numbers.each do |invalid_phone_number|
          expect(n.validate_each(object, attribute, invalid_phone_number)).to include('Test error message')
        end
      end
    end

  end

  context 'Correct phone number 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_phone_numbers.each do |valid_phone_number|
          expect(n.validate_each(object, attribute, valid_phone_number)).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_phone_numbers.each do |valid_phone_number|
          expect(n.validate_each(object, attribute, valid_phone_number)).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/phone_number_format_validator_spec.rb
ama_validators-0.0.12 spec/phone_number_format_validator_spec.rb
ama_validators-0.0.11 spec/phone_number_format_validator_spec.rb
ama_validators-0.0.10 spec/phone_number_format_validator_spec.rb
ama_validators-0.0.9 spec/phone_number_format_validator_spec.rb
ama_validators-0.0.8 spec/phone_number_format_validator_spec.rb
ama_validators-0.0.7 spec/phone_number_format_validator_spec.rb
ama_validators-0.0.6 spec/phone_number_format_validator_spec.rb
ama_validators-0.0.5 spec/phone_number_format_validator_spec.rb
ama_validators-0.0.4 spec/phone_number_format_validator_spec.rb