Sha256: f3288989dae924340f2125a2761a94e89725f2c43a1fe041785f38f13acbc266

Contents?: true

Size: 1.9 KB

Versions: 1

Compression:

Stored size: 1.9 KB

Contents

require 'spec_helper'

describe Individual do
  it { is_expected.to be_a_kind_of Persona::Individual }

  it { is_expected.to belong_to(:place_of_birth) }

  it { is_expected.to have_one(:identity).dependent(:destroy) }
  it { is_expected.to have_one(:person) }

  it { is_expected.to validate_presence_of :gender }

  it { is_expected.to allow_value('744.230.230-08').for(:cpf) }
  it { is_expected.to allow_value('').for(:cpf) }
  it { is_expected.to allow_value(nil).for(:cpf) }
  it { is_expected.not_to allow_value('744.230.230-09').for(:cpf) }
  it { is_expected.not_to allow_value('74423023008').for(:cpf) }

  context 'cpf filled with zeros' do
    before do
      subject.cpf = '000.000.000-00'
    end

    it { is_expected.to allow_value('000.000.000-00').for(:cpf) }
    it { is_expected.to allow_value('003.151.987-37').for(:cpf) }
    it { is_expected.to allow_value('').for(:cpf) }
    it { is_expected.to allow_value(nil).for(:cpf) }
    it { is_expected.not_to allow_value('00000000000').for(:cpf) }
  end

  context 'cpf uniqueness validation' do
    it { is_expected.to validate_uniqueness_of :cpf }

    context 'when validate_cpf_uniqueness? returns false' do
      before do
        allow_any_instance_of(described_class).to receive_messages validate_cpf_uniqueness?: false
      end

      it { is_expected.not_to validate_uniqueness_of :cpf }
    end
  end

  it 'should allow past dates for birthdate' do
    expect(subject).to allow_value(Date.yesterday).for(:birthdate)
  end

  it 'should not allow today for birthdate' do
    expect(subject).to_not allow_value(Date.current).for(:birthdate)
  end

  it 'should not allow future dates for birthdate' do
    expect(subject).to_not allow_value(Date.tomorrow).for(:birthdate)
  end

  it 'cast to string using person name' do
    allow(subject).to receive(:person).and_return(double(name: 'Gabriel Sobrinho'))

    expect(subject.to_s).to eq 'Gabriel Sobrinho'
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unico-training-7.8.0 spec/models/individual_spec.rb