Sha256: 472bac603ff40d62cc6de1491cfa2806885663d400d2d684eceae59e3b9efcf9

Contents?: true

Size: 1.4 KB

Versions: 2

Compression:

Stored size: 1.4 KB

Contents

require 'factories/profiles.rb'

describe PostalCodeFormatValidator do

  let(:subject) { PostalCodeFormatValidator }

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


  context 'Wrong postal code 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 } )
        expect(n.validate_each(object, attribute, 'TTJ4M5')).to include('enter a valid AB or NT postal code (e.g. T2T 2T2)')
      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 } )
        expect(n.validate_each(object, attribute, 'G7J4M5')).to include('Test error message')
      end
    end

  end

  context 'Correct postal code format' do

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

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

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ama_validators-0.0.3 spec/postal_code_format_validator_spec.rb
ama_validators-0.0.2 spec/postal_code_format_validator_spec.rb