Sha256: 38a293e3a0b1fe2ea85ec02181eac612f7f3c64ad5c40d73ee6d90b39dd0fec5

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents

require 'rails_helper'

module Popolo
  RSpec.describe Person do
    [:birth_date, :death_date].each do |attribute|
      it_behaves_like 'a model with a date attribute', attribute
    end

    describe '#to_s' do
      it 'should return the name if the name, given name and family name are blank' do
        expect(FactoryGirl.build(:person, name: nil).to_s).to eq(nil)
      end

      it 'should return the given name and family name if the name is blank' do
        expect(FactoryGirl.build(:person, name: nil, given_name: 'John', family_name: 'Public').to_s).to eq('John Public')
      end

      it 'should return the family name if the name and given name are blank' do
        expect(FactoryGirl.build(:person, name: nil, family_name: 'Public').to_s).to eq('Public')
      end

      it 'should return the given name if the name and family name are blank' do
        expect(FactoryGirl.build(:person, name: nil, given_name: 'John').to_s).to eq('John')
      end

      it 'should return the name if present' do
        expect(FactoryGirl.build(:person, given_name: 'John', family_name: 'Public').to_s).to eq('John Q. Public')
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
popolo-0.1.1 spec/models/popolo/person_spec.rb
popolo-0.1.0 spec/models/popolo/person_spec.rb