Sha256: 0fa2427593e5f80a819727d249095c8dd88c105600b6592bd8b5101dee81658e

Contents?: true

Size: 1.04 KB

Versions: 4

Compression:

Stored size: 1.04 KB

Contents

require 'spec_helper'

describe CpfValidator do
  context 'when cpf is invalid' do
    context 'on a non namespaced model' do
      before :each do
        @user = User.new(:cpf => '12345')
        I18n.stub(:t).with(:'activerecord.errors.models.user.attributes.cpf.invalid',
                           :default => :'activerecord.errors.messages.invalid').and_return('is invalid')
      end

      it 'should set object as invalid' do
        @user.valid?.should be_false
      end

      it 'should set an error message on attribute' do
        @user.valid?
        @user.errors[:cpf].should == ['is invalid']
      end
    end
  end

  context 'when cpf is valid' do
    before :each do
      @user = User.new(:cpf => '11144477735')
    end

    it 'should set object as valid' do
      @user.valid?.should be_true
    end

    it 'should not set an error message on attribute' do
      @user.valid?
      @user.errors[:cpf].should be_blank
    end
  end

  it 'should accept a nil value' do
    @user = User.new(:cpf => nil)
    @user.valid?.should be_true
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
validates_cpf-2.0.1 spec/validates_cpf_spec.rb
validates_cpf-2.0.0 spec/validates_cpf_spec.rb
validates_cpf-2.0.0.rc2 spec/validates_cpf_spec.rb
validates_cpf-2.0.0.rc1 spec/validates_cpf_spec.rb