Sha256: 46a965c9f8632e04f667f22ceb04431b019991f128899139032242ea4d7f4b9b

Contents?: true

Size: 1.45 KB

Versions: 2

Compression:

Stored size: 1.45 KB

Contents

require 'factories/profiles.rb'

describe CreditCardFormatValidator do

  let(:subject) { CreditCardFormatValidator }

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


  context 'Wrong credit card 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, '9485582751367890')).to include('enter a valid credit card number (Visa or Mastercard)')
      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 } )
        expect(n.validate_each(object, attribute, '9485582751367890')).to include('Test error message')
      end
    end

  end

  context 'Correct credit card 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, '4716157014589654')).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, '5595361193388663')).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/credit_card_format_validator_spec.rb
ama_validators-0.0.2 spec/credit_card_format_validator_spec.rb