2018-12-09 22:32:35 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Person do
|
2019-07-20 05:53:51 -04:00
|
|
|
subject { create :initial_person }
|
2018-12-09 22:32:35 -05:00
|
|
|
|
2019-03-26 18:06:03 -04:00
|
|
|
it_behaves_like 'nameable'
|
|
|
|
|
2019-07-20 06:07:02 -04:00
|
|
|
describe '#account' do
|
|
|
|
it { is_expected.to have_one(:account).dependent(:restrict_with_exception) }
|
2019-07-20 05:53:51 -04:00
|
|
|
end
|
|
|
|
|
2019-07-20 06:07:02 -04:00
|
|
|
describe '#contacts_list' do
|
|
|
|
xit { is_expected.to belong_to(:contacts_list).required }
|
2019-07-15 17:19:11 -04:00
|
|
|
end
|
|
|
|
|
2019-07-20 08:16:48 -04:00
|
|
|
describe '#all_relationships' do
|
2019-04-28 10:12:02 -04:00
|
|
|
let! :relationship_2 do
|
2019-07-20 02:02:32 -04:00
|
|
|
create :supporter_relationship,
|
|
|
|
person: subject,
|
2019-07-20 02:22:47 -04:00
|
|
|
from_date: 4.days.ago
|
2019-04-28 10:12:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
let! :relationship_3 do
|
2019-07-20 02:02:32 -04:00
|
|
|
create :supporter_relationship,
|
|
|
|
person: subject,
|
2019-07-20 02:22:47 -04:00
|
|
|
from_date: 2.days.ago
|
2019-04-28 10:12:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
let! :relationship_1 do
|
2019-07-20 02:02:32 -04:00
|
|
|
create :supporter_relationship,
|
|
|
|
person: subject,
|
2019-07-20 02:22:47 -04:00
|
|
|
from_date: 6.days.ago
|
2019-04-28 10:12:02 -04:00
|
|
|
end
|
|
|
|
|
2019-07-20 06:07:02 -04:00
|
|
|
it do
|
|
|
|
is_expected.to \
|
2019-07-20 08:16:48 -04:00
|
|
|
have_many(:all_relationships)
|
|
|
|
.class_name('Relationship')
|
2019-07-20 06:07:02 -04:00
|
|
|
.inverse_of(:person)
|
|
|
|
.dependent(:restrict_with_exception)
|
|
|
|
.order(from_date: :asc)
|
|
|
|
end
|
|
|
|
|
2019-04-28 10:12:02 -04:00
|
|
|
specify do
|
2019-07-20 08:16:48 -04:00
|
|
|
expect(subject.all_relationships).to eq [
|
2019-04-28 10:12:02 -04:00
|
|
|
relationship_1,
|
|
|
|
relationship_2,
|
|
|
|
relationship_3,
|
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-28 10:20:28 -04:00
|
|
|
describe '#current_relationship' do
|
2019-07-20 06:07:02 -04:00
|
|
|
it do
|
|
|
|
is_expected.to \
|
|
|
|
have_one(:current_relationship)
|
|
|
|
.class_name('Relationship')
|
|
|
|
.inverse_of(:person)
|
|
|
|
.dependent(:restrict_with_exception)
|
|
|
|
.order(from_date: :desc)
|
|
|
|
end
|
|
|
|
|
2019-04-28 10:20:28 -04:00
|
|
|
let! :relationship_2 do
|
2019-07-20 02:02:32 -04:00
|
|
|
create :supporter_relationship,
|
|
|
|
person: subject,
|
2019-07-20 02:22:47 -04:00
|
|
|
from_date: 4.days.ago
|
2019-04-28 10:20:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
let! :relationship_3 do
|
2019-07-20 02:02:32 -04:00
|
|
|
create :supporter_relationship,
|
|
|
|
person: subject,
|
2019-07-20 02:22:47 -04:00
|
|
|
from_date: 2.days.ago
|
2019-04-28 10:20:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
let! :relationship_1 do
|
2019-07-20 02:02:32 -04:00
|
|
|
create :supporter_relationship,
|
|
|
|
person: subject,
|
2019-07-20 02:22:47 -04:00
|
|
|
from_date: 6.days.ago
|
2019-04-28 10:20:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
specify do
|
|
|
|
expect(subject.current_relationship).to eq relationship_3
|
|
|
|
end
|
|
|
|
end
|
2019-07-20 06:07:02 -04:00
|
|
|
|
2019-07-20 08:01:24 -04:00
|
|
|
describe '#current_regional_office' do
|
2019-07-20 06:07:02 -04:00
|
|
|
it do
|
|
|
|
is_expected.to \
|
2019-07-20 08:01:24 -04:00
|
|
|
have_one(:current_regional_office)
|
2019-07-20 07:56:26 -04:00
|
|
|
.inverse_of(:all_people)
|
2019-07-20 06:07:02 -04:00
|
|
|
.through(:current_relationship)
|
|
|
|
.source(:regional_office)
|
|
|
|
.dependent(:restrict_with_exception)
|
|
|
|
end
|
|
|
|
|
2019-07-20 08:01:24 -04:00
|
|
|
it { is_expected.not_to validate_presence_of :current_regional_office }
|
2019-07-20 06:07:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#person_comments' do
|
|
|
|
it do
|
|
|
|
is_expected.to \
|
|
|
|
have_many(:person_comments)
|
|
|
|
.dependent(:restrict_with_exception)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#passports' do
|
|
|
|
it do
|
|
|
|
is_expected.to \
|
|
|
|
have_many(:passports)
|
|
|
|
.dependent(:restrict_with_exception)
|
|
|
|
end
|
|
|
|
end
|
2018-12-09 22:32:35 -05:00
|
|
|
end
|