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/relationship_spec.rb

354 lines
12 KiB
Ruby
Raw Normal View History

2019-04-27 10:24:04 -04:00
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Relationship do
subject { create :supporter_relationship }
2019-07-20 06:07:02 -04:00
describe '#person' do
it do
is_expected.to belong_to(:person).inverse_of(:all_relationships).required
end
2019-07-20 06:07:02 -04:00
end
describe '#regional_office' do
it do
is_expected.to \
belong_to(:regional_office).inverse_of(:all_relationships).required
end
2019-07-20 06:07:02 -04:00
end
2019-04-28 08:48:51 -04:00
describe '#from_date' do
it { is_expected.to validate_presence_of :from_date }
2019-04-28 09:24:01 -04:00
it do
is_expected.to \
validate_uniqueness_of(:from_date)
2019-07-20 02:02:32 -04:00
.scoped_to(:person_id)
2019-04-28 09:24:01 -04:00
end
end
2019-06-04 22:33:45 -04:00
describe '#status' do
it { is_expected.to validate_presence_of :status }
end
2019-07-20 05:12:58 -04:00
describe '#role' do
2019-07-21 22:30:58 -04:00
def allow_value(*)
super.for :role
end
2019-07-20 05:12:58 -04:00
context 'for supporter relationship' do
subject { create :supporter_relationship }
2019-07-21 22:30:58 -04:00
it { is_expected.to allow_value nil }
it { is_expected.not_to allow_value described_class.roles.keys.sample }
2019-07-20 05:12:58 -04:00
end
2019-07-26 00:07:18 -04:00
context 'for excluded relationship' do
subject { create :excluded_relationship }
2019-07-20 05:12:58 -04:00
2019-07-21 22:30:58 -04:00
it { is_expected.to allow_value nil }
it { is_expected.not_to allow_value described_class.roles.keys.sample }
2019-07-20 05:12:58 -04:00
end
context 'for member relationship' do
subject { create :member_relationship }
2019-07-21 22:30:58 -04:00
it { is_expected.to allow_value nil }
it { is_expected.to allow_value described_class.roles.keys.sample }
2019-07-20 05:12:58 -04:00
end
end
2019-07-25 22:06:01 -04:00
describe '#federal_secretary_flag' do
def allow_value(*)
super.for :federal_secretary_flag
end
context 'for supporter relationship' do
subject { create :supporter_relationship }
it { is_expected.to allow_value nil }
it { is_expected.not_to allow_value :federal_secretary }
end
2019-07-26 00:07:18 -04:00
context 'for excluded relationship' do
subject { create :excluded_relationship }
it { is_expected.to allow_value nil }
it { is_expected.not_to allow_value :federal_secretary }
end
context 'for member relationship' do
subject { create :member_relationship }
it { is_expected.to allow_value nil }
it { is_expected.not_to allow_value :federal_secretary }
end
context 'for federal manager relationship' do
subject { create :federal_manager_relationship }
it { is_expected.to allow_value nil }
it { is_expected.to allow_value :federal_secretary }
context 'when federal secretary already exists' do
subject { create :federal_secretary_relationship }
it do
is_expected.to \
validate_uniqueness_of(:federal_secretary_flag)
.allow_nil
.ignoring_case_sensitivity
end
end
end
context 'for federal supervisor relationship' do
subject { create :federal_supervisor_relationship }
it { is_expected.to allow_value nil }
it { is_expected.not_to allow_value :federal_secretary }
end
context 'for regional manager relationship' do
subject { create :regional_manager_relationship }
it { is_expected.to allow_value nil }
it { is_expected.not_to allow_value :federal_secretary }
end
context 'for regional supervisor relationship' do
subject { create :regional_supervisor_relationship }
it { is_expected.to allow_value nil }
it { is_expected.not_to allow_value :federal_secretary }
end
end
describe '#regional_secretary_flag' do
def allow_value(*)
super.for :regional_secretary_flag
end
context 'for supporter relationship' do
subject { create :supporter_relationship }
it { is_expected.to allow_value nil }
it { is_expected.not_to allow_value :regional_secretary }
end
2019-07-26 00:07:18 -04:00
context 'for excluded relationship' do
subject { create :excluded_relationship }
it { is_expected.to allow_value nil }
it { is_expected.not_to allow_value :regional_secretary }
end
context 'for member relationship' do
subject { create :member_relationship }
it { is_expected.to allow_value nil }
it { is_expected.not_to allow_value :regional_secretary }
end
context 'for federal manager relationship' do
subject { create :federal_manager_relationship }
it { is_expected.to allow_value nil }
it { is_expected.not_to allow_value :regional_secretary }
end
context 'for federal supervisor relationship' do
subject { create :federal_supervisor_relationship }
it { is_expected.to allow_value nil }
it { is_expected.not_to allow_value :regional_secretary }
end
context 'for regional manager relationship' do
subject { create :regional_manager_relationship }
it { is_expected.to allow_value nil }
it { is_expected.to allow_value :regional_secretary }
context 'when regional secretary already exists' do
subject { create :regional_secretary_relationship }
it do
is_expected.to \
validate_uniqueness_of(:regional_secretary_flag)
.allow_nil
.ignoring_case_sensitivity
.scoped_to(:regional_office_id)
end
end
end
context 'for regional supervisor relationship' do
subject { create :regional_supervisor_relationship }
it { is_expected.to allow_value nil }
it { is_expected.not_to allow_value :regional_secretary }
end
end
2019-07-25 23:50:30 -04:00
describe '.supporters' do
let!(:relationship1) { create :supporter_relationship }
let!(:relationship2) { create :member_relationship }
2019-07-26 00:07:18 -04:00
let!(:relationship3) { create :excluded_relationship }
let!(:relationship3) { create :excluded_relationship }
2019-07-25 23:50:30 -04:00
let!(:relationship4) { create :federal_manager_relationship }
let!(:relationship5) { create :federal_supervisor_relationship }
let!(:relationship6) { create :regional_manager_relationship }
let!(:relationship7) { create :regional_supervisor_relationship }
let!(:relationship8) { create :supporter_relationship }
specify do
expect(described_class.supporters).to \
eq [relationship1, relationship8]
end
end
describe '.excluded' do
let!(:relationship1) { create :supporter_relationship }
let!(:relationship2) { create :member_relationship }
2019-07-26 00:07:18 -04:00
let!(:relationship3) { create :excluded_relationship }
let!(:relationship4) { create :excluded_relationship }
2019-07-25 23:50:30 -04:00
let!(:relationship5) { create :federal_manager_relationship }
let!(:relationship6) { create :federal_supervisor_relationship }
let!(:relationship7) { create :regional_manager_relationship }
let!(:relationship8) { create :regional_supervisor_relationship }
2019-07-26 00:07:18 -04:00
let!(:relationship9) { create :excluded_relationship }
2019-07-25 23:50:30 -04:00
specify do
expect(described_class.excluded).to \
eq [relationship3, relationship4, relationship9]
end
end
describe '.members' do
let!(:relationship1) { create :supporter_relationship }
let!(:relationship2) { create :member_relationship }
2019-07-26 00:07:18 -04:00
let!(:relationship3) { create :excluded_relationship }
let!(:relationship4) { create :excluded_relationship }
2019-07-25 23:50:30 -04:00
let!(:relationship5) { create :federal_manager_relationship }
let!(:relationship6) { create :federal_supervisor_relationship }
let!(:relationship7) { create :regional_manager_relationship }
let!(:relationship8) { create :regional_supervisor_relationship }
let!(:relationship9) { create :member_relationship }
specify do
expect(described_class.members).to eq [
relationship2,
relationship5,
relationship6,
relationship7,
relationship8,
relationship9,
]
end
end
2019-07-25 22:06:01 -04:00
describe '.federal_managers' do
let!(:relationship1) { create :supporter_relationship }
let!(:relationship2) { create :member_relationship }
2019-07-26 00:07:18 -04:00
let!(:relationship3) { create :excluded_relationship }
let!(:relationship3) { create :excluded_relationship }
2019-07-25 22:06:01 -04:00
let!(:relationship4) { create :federal_manager_relationship }
2019-07-25 22:09:52 -04:00
let!(:relationship5) { create :federal_supervisor_relationship }
let!(:relationship6) { create :regional_manager_relationship }
let!(:relationship7) { create :regional_supervisor_relationship }
let!(:relationship8) { create :federal_manager_relationship }
2019-07-25 22:06:01 -04:00
specify do
expect(described_class.federal_managers).to \
2019-07-25 22:09:52 -04:00
eq [relationship4, relationship8]
end
end
describe '.federal_supervisors' do
let!(:relationship1) { create :supporter_relationship }
let!(:relationship2) { create :member_relationship }
2019-07-26 00:07:18 -04:00
let!(:relationship3) { create :excluded_relationship }
let!(:relationship3) { create :excluded_relationship }
2019-07-25 22:09:52 -04:00
let!(:relationship4) { create :federal_manager_relationship }
let!(:relationship5) { create :federal_supervisor_relationship }
let!(:relationship6) { create :regional_manager_relationship }
let!(:relationship7) { create :regional_supervisor_relationship }
let!(:relationship8) { create :federal_supervisor_relationship }
specify do
expect(described_class.federal_supervisors).to \
eq [relationship5, relationship8]
2019-07-25 22:06:01 -04:00
end
end
describe '.federal_secretaries' do
let!(:relationship1) { create :supporter_relationship }
let!(:relationship2) { create :member_relationship }
2019-07-26 00:07:18 -04:00
let!(:relationship3) { create :excluded_relationship }
let!(:relationship3) { create :excluded_relationship }
let!(:relationship4) { create :federal_manager_relationship }
let!(:relationship5) { create :federal_supervisor_relationship }
let!(:relationship6) { create :regional_manager_relationship }
let!(:relationship7) { create :regional_supervisor_relationship }
let!(:relationship8) { create :federal_secretary_relationship }
let!(:relationship9) { create :federal_manager_relationship }
specify do
expect(described_class.federal_secretaries).to eq [relationship8]
end
end
2019-07-25 23:50:30 -04:00
describe '.regional_managers' do
let!(:relationship1) { create :supporter_relationship }
let!(:relationship2) { create :member_relationship }
2019-07-26 00:07:18 -04:00
let!(:relationship3) { create :excluded_relationship }
let!(:relationship3) { create :excluded_relationship }
2019-07-25 23:50:30 -04:00
let!(:relationship4) { create :federal_manager_relationship }
let!(:relationship5) { create :federal_supervisor_relationship }
let!(:relationship6) { create :regional_manager_relationship }
let!(:relationship7) { create :regional_supervisor_relationship }
let!(:relationship8) { create :regional_manager_relationship }
specify do
expect(described_class.regional_managers).to \
eq [relationship6, relationship8]
end
end
describe '.regional_supervisors' do
let!(:relationship1) { create :supporter_relationship }
let!(:relationship2) { create :member_relationship }
2019-07-26 00:07:18 -04:00
let!(:relationship3) { create :excluded_relationship }
let!(:relationship3) { create :excluded_relationship }
2019-07-25 23:50:30 -04:00
let!(:relationship4) { create :federal_manager_relationship }
let!(:relationship5) { create :federal_supervisor_relationship }
let!(:relationship6) { create :regional_manager_relationship }
let!(:relationship7) { create :regional_supervisor_relationship }
let!(:relationship8) { create :regional_supervisor_relationship }
specify do
expect(described_class.regional_supervisors).to \
eq [relationship7, relationship8]
end
end
describe '.regional_secretaries' do
let!(:relationship1) { create :supporter_relationship }
let!(:relationship2) { create :member_relationship }
2019-07-26 00:07:18 -04:00
let!(:relationship3) { create :excluded_relationship }
let!(:relationship3) { create :excluded_relationship }
let!(:relationship4) { create :federal_manager_relationship }
let!(:relationship5) { create :federal_supervisor_relationship }
let!(:relationship6) { create :regional_manager_relationship }
let!(:relationship7) { create :regional_supervisor_relationship }
let!(:relationship8) { create :regional_secretary_relationship }
let!(:relationship9) { create :regional_manager_relationship }
specify do
expect(described_class.regional_secretaries).to eq [relationship8]
end
end
2019-04-27 10:24:04 -04:00
end