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

239 lines
6.2 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
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) }
2018-12-10 03:36:09 +00:00
it do
is_expected.to \
2018-12-15 04:20:13 +00:00
have_one(:own_membership_app)
.class_name('MembershipApp')
.inverse_of(:person)
.through(:account)
.source(:own_membership_app)
2018-12-10 03:36:09 +00:00
end
2018-12-15 04:09:43 +00:00
it { is_expected.not_to validate_presence_of :regional_office }
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