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

300 lines
7.5 KiB
Ruby
Raw Normal View History

2018-12-10 03:32:35 +00:00
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Person do
subject { create :member_person }
2018-12-10 03:32:35 +00:00
2019-03-26 22:06:03 +00:00
it_behaves_like 'nameable'
2018-12-15 05:54:45 +00:00
it { is_expected.to belong_to(:regional_office).optional }
2018-12-15 04:09:43 +00:00
2018-12-15 04:20:13 +00:00
it { is_expected.to have_one(:account).dependent(:restrict_with_exception) }
2019-04-28 13:08:02 +00:00
it do
is_expected.to \
have_many(:relationships)
2019-04-28 14:12:02 +00:00
.inverse_of(:person)
2019-04-28 13:08:02 +00:00
.dependent(:restrict_with_exception)
2019-04-28 14:12:02 +00:00
.order(number: :asc)
2019-04-28 13:08:02 +00:00
end
it do
is_expected.to \
have_one(:current_relationship)
.class_name('Relationship')
.inverse_of(:person)
.order(number: :desc)
end
it do
is_expected.to \
have_many(:passports)
.dependent(:restrict_with_exception)
end
2019-03-25 23:11:52 +00:00
it do
is_expected.to \
have_many(:resident_registrations)
.dependent(:restrict_with_exception)
end
2018-12-15 04:09:43 +00:00
it { is_expected.not_to validate_presence_of :regional_office }
2019-04-28 14:12:02 +00:00
describe '#relationships' do
let! :relationship_2 do
create :supporter_relationship, person: subject, number: 2
end
let! :relationship_3 do
create :supporter_relationship, person: subject, number: 3
end
let! :relationship_1 do
create :supporter_relationship, person: subject, number: 1
end
specify do
expect(subject.relationships).to eq [
relationship_1,
relationship_2,
relationship_3,
]
end
end
describe '#current_relationship' do
let! :relationship_2 do
create :supporter_relationship, person: subject, number: 2
end
let! :relationship_3 do
create :supporter_relationship, person: subject, number: 3
end
let! :relationship_1 do
create :supporter_relationship, person: subject, number: 1
end
specify do
expect(subject.current_relationship).to eq relationship_3
end
end
2018-12-15 05:51:44 +00:00
describe '#supporter_since' do
def allow_value(*)
super.for :supporter_since
end
it { is_expected.not_to validate_presence_of :supporter_since }
it { is_expected.to allow_value Time.zone.today }
it { is_expected.to allow_value Time.zone.yesterday }
it { is_expected.to allow_value rand(10_000).days.ago.to_date }
it { is_expected.not_to allow_value Time.zone.tomorrow }
it { is_expected.not_to allow_value 1.day.from_now.to_date }
it { is_expected.not_to allow_value rand(10_000).days.from_now.to_date }
context 'for initial person' do
subject { create :initial_person }
it { is_expected.to allow_value nil }
it { is_expected.to allow_value Time.zone.today }
end
context 'for supporter person' do
subject { create :supporter_person }
it { is_expected.to allow_value nil }
it { is_expected.to allow_value Time.zone.today }
end
context 'for member person' do
subject { create :member_person }
it { is_expected.to allow_value nil }
it { is_expected.to allow_value Time.zone.today }
end
context 'for excluded person' do
subject { create :excluded_person }
it { is_expected.to allow_value nil }
it { is_expected.to allow_value Time.zone.today }
end
2018-12-15 05:51:44 +00:00
end
2018-12-15 06:03:44 +00:00
2019-01-29 01:42:25 +00:00
describe '#member_since' do
def allow_value(*)
super.for :member_since
end
it { is_expected.not_to validate_presence_of :member_since }
it { is_expected.to allow_value Time.zone.today }
it { is_expected.to allow_value Time.zone.yesterday }
it { is_expected.to allow_value subject.supporter_since + rand(500) }
2019-01-29 01:42:25 +00:00
it { is_expected.not_to allow_value Time.zone.tomorrow }
it { is_expected.not_to allow_value 1.day.from_now.to_date }
it { is_expected.not_to allow_value rand(10_000).days.from_now.to_date }
context 'for initial person' do
subject { create :initial_person }
it { is_expected.to allow_value nil }
it { is_expected.not_to allow_value Time.zone.today }
end
context 'for supporter person' do
subject { create :supporter_person }
it { is_expected.to allow_value nil }
it { is_expected.to allow_value Time.zone.today }
end
context 'for member person' do
subject { create :member_person }
it { is_expected.to allow_value nil }
it { is_expected.to allow_value Time.zone.today }
end
context 'for excluded person' do
subject { create :excluded_person }
it { is_expected.to allow_value nil }
it { is_expected.to allow_value Time.zone.today }
end
2019-01-29 01:42:25 +00:00
end
describe '#excluded_since' do
def allow_value(*)
super.for :excluded_since
end
it { is_expected.not_to validate_presence_of :excluded_since }
it { is_expected.to allow_value Time.zone.today }
it { is_expected.to allow_value Time.zone.yesterday }
it { is_expected.to allow_value subject.member_since + rand(500) }
it { is_expected.not_to allow_value Time.zone.tomorrow }
it { is_expected.not_to allow_value 1.day.from_now.to_date }
it { is_expected.not_to allow_value rand(10_000).days.from_now.to_date }
context 'for initial person' do
subject { create :initial_person }
it { is_expected.to allow_value nil }
it { is_expected.not_to allow_value Time.zone.today }
end
context 'for supporter person' do
subject { create :supporter_person }
it { is_expected.to allow_value nil }
it { is_expected.to allow_value Time.zone.today }
end
context 'for member person' do
subject { create :member_person }
it { is_expected.to allow_value nil }
it { is_expected.to allow_value Time.zone.today }
end
context 'for excluded person' do
subject { create :excluded_person }
it { is_expected.to allow_value nil }
it { is_expected.to allow_value Time.zone.today }
end
end
2018-12-15 06:03:44 +00:00
describe '#party_supporter?' do
let(:result) { subject.party_supporter? }
context 'for initial person' do
subject { create :initial_person }
specify { expect(result).to eq false }
end
2018-12-15 06:03:44 +00:00
context 'for party supporter' do
subject { create :supporter_person }
specify { expect(result).to eq true }
end
2019-01-29 01:52:35 +00:00
context 'for party member' do
subject { create :member_person }
specify { expect(result).to eq true }
end
context 'for excluded party member' do
subject { create :excluded_person }
specify { expect(result).to eq false }
end
2019-01-29 01:52:35 +00:00
end
describe '#party_member?' do
let(:result) { subject.party_member? }
context 'for initial person' do
subject { create :initial_person }
specify { expect(result).to eq false }
end
2019-01-29 01:52:35 +00:00
context 'for party supporter' do
subject { create :supporter_person }
specify { expect(result).to eq false }
end
context 'for party member' do
subject { create :member_person }
specify { expect(result).to eq true }
end
context 'for excluded party member' do
subject { create :excluded_person }
specify { expect(result).to eq false }
end
end
describe '#excluded_from_party?' do
let(:result) { subject.excluded_from_party? }
context 'for initial person' do
subject { create :initial_person }
specify { expect(result).to eq false }
end
context 'for party supporter' do
subject { create :supporter_person }
specify { expect(result).to eq false }
end
context 'for party member' do
subject { create :member_person }
specify { expect(result).to eq false }
end
context 'for excluded party member' do
subject { create :excluded_person }
specify { expect(result).to eq true }
end
2018-12-15 06:03:44 +00:00
end
2018-12-10 03:32:35 +00:00
end