1
0
Fork 0
This repository has been archived on 2023-03-27. You can view files and clone it, but cannot push or open issues or pull requests.
lpr-partynest/spec/models/person_spec.rb

98 lines
2.1 KiB
Ruby
Raw Normal View History

2018-12-09 22:32:35 -05:00
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Person do
subject { create :member_person }
2018-12-09 22:32:35 -05:00
2019-03-26 18:06:03 -04:00
it_behaves_like 'nameable'
2018-12-15 00:54:45 -05:00
it { is_expected.to belong_to(:regional_office).optional }
2018-12-14 23:09:43 -05:00
2019-06-26 20:21:37 -04:00
xit { is_expected.to belong_to(:contacts_list).required }
2018-12-14 23:20:13 -05:00
it { is_expected.to have_one(:account).dependent(:restrict_with_exception) }
2019-04-28 09:08:02 -04:00
it do
is_expected.to \
have_many(:relationships)
2019-04-28 10:12:02 -04:00
.inverse_of(:person)
2019-04-28 09:08:02 -04:00
.dependent(:restrict_with_exception)
2019-07-20 02:02:32 -04:00
.order(active_since: :asc)
2019-04-28 09:08:02 -04:00
end
it do
is_expected.to \
have_one(:current_relationship)
.class_name('Relationship')
.inverse_of(:person)
2019-07-20 02:02:32 -04:00
.order(active_since: :desc)
end
2019-07-15 17:19:11 -04:00
it do
is_expected.to \
have_many(:person_comments)
.dependent(:restrict_with_exception)
end
it do
is_expected.to \
have_many(:passports)
.dependent(:restrict_with_exception)
2019-03-25 19:11:52 -04:00
end
2018-12-14 23:09:43 -05:00
it { is_expected.not_to validate_presence_of :regional_office }
2019-04-28 10:12:02 -04:00
describe '#relationships' do
let! :relationship_2 do
2019-07-20 02:02:32 -04:00
create :supporter_relationship,
person: subject,
active_since: 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,
active_since: 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,
active_since: 6.days.ago
2019-04-28 10:12:02 -04:00
end
specify do
expect(subject.relationships).to eq [
relationship_1,
relationship_2,
relationship_3,
]
end
end
describe '#current_relationship' do
let! :relationship_2 do
2019-07-20 02:02:32 -04:00
create :supporter_relationship,
person: subject,
active_since: 4.days.ago
end
let! :relationship_3 do
2019-07-20 02:02:32 -04:00
create :supporter_relationship,
person: subject,
active_since: 2.days.ago
end
let! :relationship_1 do
2019-07-20 02:02:32 -04:00
create :supporter_relationship,
person: subject,
active_since: 6.days.ago
end
specify do
expect(subject.current_relationship).to eq relationship_3
end
end
2018-12-09 22:32:35 -05:00
end