2018-12-06 17:49:50 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe RegionalOffice do
|
|
|
|
subject { create :regional_office }
|
|
|
|
|
2019-07-20 06:07:02 -04:00
|
|
|
describe '#federal_subject' do
|
|
|
|
it { is_expected.to belong_to :federal_subject }
|
2018-12-06 17:49:50 -05:00
|
|
|
|
2019-07-20 06:07:02 -04:00
|
|
|
it do
|
|
|
|
is_expected.to \
|
|
|
|
validate_presence_of(:federal_subject)
|
|
|
|
.with_message(:required)
|
|
|
|
end
|
2019-04-28 09:06:22 -04:00
|
|
|
|
2019-07-20 06:07:02 -04:00
|
|
|
it { is_expected.to validate_uniqueness_of :federal_subject }
|
2019-07-20 05:53:51 -04:00
|
|
|
end
|
|
|
|
|
2019-07-20 06:07:02 -04:00
|
|
|
describe '#relationships' do
|
|
|
|
it do
|
|
|
|
is_expected.to \
|
|
|
|
have_many(:relationships)
|
2019-07-20 06:46:49 -04:00
|
|
|
.inverse_of(:regional_office)
|
|
|
|
.dependent(:restrict_with_exception)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-20 07:38:12 -04:00
|
|
|
describe '#current_relationships' do
|
|
|
|
it do
|
|
|
|
is_expected.to \
|
|
|
|
have_many(:current_relationships)
|
|
|
|
.class_name('Relationship')
|
|
|
|
.inverse_of(:regional_office)
|
|
|
|
.dependent(:restrict_with_exception)
|
|
|
|
.order(person_id: :asc, from_date: :desc)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-20 07:46:46 -04:00
|
|
|
describe '#current_supporter_relationships' do
|
2019-07-20 06:46:49 -04:00
|
|
|
it do
|
|
|
|
is_expected.to \
|
2019-07-20 07:46:46 -04:00
|
|
|
have_many(:current_supporter_relationships)
|
2019-07-20 06:46:49 -04:00
|
|
|
.class_name('Relationship')
|
|
|
|
.inverse_of(:regional_office)
|
2019-07-20 06:07:02 -04:00
|
|
|
.dependent(:restrict_with_exception)
|
2019-07-20 06:46:49 -04:00
|
|
|
.conditions(status: :supporter)
|
2019-07-20 07:46:46 -04:00
|
|
|
.order(person_id: :asc, from_date: :desc)
|
2019-07-20 06:46:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-20 07:46:46 -04:00
|
|
|
describe '#current_member_relationships' do
|
2019-07-20 06:46:49 -04:00
|
|
|
it do
|
|
|
|
is_expected.to \
|
2019-07-20 07:46:46 -04:00
|
|
|
have_many(:current_member_relationships)
|
2019-07-20 06:46:49 -04:00
|
|
|
.class_name('Relationship')
|
|
|
|
.inverse_of(:regional_office)
|
|
|
|
.dependent(:restrict_with_exception)
|
|
|
|
.conditions(status: :member)
|
2019-07-20 07:46:46 -04:00
|
|
|
.order(person_id: :asc, from_date: :desc)
|
2019-07-20 06:07:02 -04:00
|
|
|
end
|
2018-12-06 17:49:50 -05:00
|
|
|
end
|
|
|
|
|
2019-07-20 07:46:46 -04:00
|
|
|
describe '#current_manager_relationships' do
|
2019-07-20 06:58:39 -04:00
|
|
|
it do
|
|
|
|
is_expected.to \
|
2019-07-20 07:46:46 -04:00
|
|
|
have_many(:current_manager_relationships)
|
2019-07-20 06:58:39 -04:00
|
|
|
.class_name('Relationship')
|
|
|
|
.inverse_of(:regional_office)
|
|
|
|
.dependent(:restrict_with_exception)
|
|
|
|
.conditions(status: :member, role: :manager)
|
2019-07-20 07:46:46 -04:00
|
|
|
.order(person_id: :asc, from_date: :desc)
|
2019-07-20 06:58:39 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-20 07:46:46 -04:00
|
|
|
describe '#current_supervisor_relationships' do
|
2019-07-20 06:58:39 -04:00
|
|
|
it do
|
|
|
|
is_expected.to \
|
2019-07-20 07:46:46 -04:00
|
|
|
have_many(:current_supervisor_relationships)
|
2019-07-20 06:58:39 -04:00
|
|
|
.class_name('Relationship')
|
|
|
|
.inverse_of(:regional_office)
|
|
|
|
.dependent(:restrict_with_exception)
|
|
|
|
.conditions(status: :member, role: :supervisor)
|
2019-07-20 07:46:46 -04:00
|
|
|
.order(person_id: :asc, from_date: :desc)
|
2019-07-20 06:58:39 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-20 06:07:02 -04:00
|
|
|
describe '#people' do
|
|
|
|
it do
|
|
|
|
is_expected.to \
|
|
|
|
have_many(:people)
|
|
|
|
.inverse_of(:regional_office)
|
|
|
|
.through(:relationships)
|
|
|
|
.source(:person)
|
|
|
|
.dependent(:restrict_with_exception)
|
|
|
|
end
|
|
|
|
end
|
2019-07-20 06:46:49 -04:00
|
|
|
|
2019-07-20 07:38:12 -04:00
|
|
|
describe '#current_people' do
|
|
|
|
it do
|
|
|
|
is_expected.to \
|
|
|
|
have_many(:current_people)
|
|
|
|
.class_name('Person')
|
|
|
|
.inverse_of(:regional_office)
|
|
|
|
.through(:current_relationships)
|
|
|
|
.source(:person)
|
|
|
|
.dependent(:restrict_with_exception)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-20 07:46:46 -04:00
|
|
|
describe '#current_supporter_people' do
|
2019-07-20 06:46:49 -04:00
|
|
|
it do
|
|
|
|
is_expected.to \
|
2019-07-20 07:46:46 -04:00
|
|
|
have_many(:current_supporter_people)
|
2019-07-20 06:46:49 -04:00
|
|
|
.class_name('Person')
|
|
|
|
.inverse_of(:regional_office)
|
2019-07-20 07:46:46 -04:00
|
|
|
.through(:current_supporter_relationships)
|
2019-07-20 06:46:49 -04:00
|
|
|
.source(:person)
|
|
|
|
.dependent(:restrict_with_exception)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-20 07:46:46 -04:00
|
|
|
describe '#current_member_people' do
|
2019-07-20 06:46:49 -04:00
|
|
|
it do
|
|
|
|
is_expected.to \
|
2019-07-20 07:46:46 -04:00
|
|
|
have_many(:current_member_people)
|
2019-07-20 06:46:49 -04:00
|
|
|
.class_name('Person')
|
|
|
|
.inverse_of(:regional_office)
|
2019-07-20 07:46:46 -04:00
|
|
|
.through(:current_member_relationships)
|
2019-07-20 06:46:49 -04:00
|
|
|
.source(:person)
|
|
|
|
.dependent(:restrict_with_exception)
|
|
|
|
end
|
|
|
|
end
|
2019-07-20 06:58:39 -04:00
|
|
|
|
2019-07-20 07:46:46 -04:00
|
|
|
describe '#current_manager_people' do
|
2019-07-20 06:58:39 -04:00
|
|
|
it do
|
|
|
|
is_expected.to \
|
2019-07-20 07:46:46 -04:00
|
|
|
have_many(:current_manager_people)
|
2019-07-20 06:58:39 -04:00
|
|
|
.class_name('Person')
|
|
|
|
.inverse_of(:regional_office)
|
2019-07-20 07:46:46 -04:00
|
|
|
.through(:current_manager_relationships)
|
2019-07-20 06:58:39 -04:00
|
|
|
.source(:person)
|
|
|
|
.dependent(:restrict_with_exception)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-20 07:46:46 -04:00
|
|
|
describe '#current_supervisor_people' do
|
2019-07-20 06:58:39 -04:00
|
|
|
it do
|
|
|
|
is_expected.to \
|
2019-07-20 07:46:46 -04:00
|
|
|
have_many(:current_supervisor_people)
|
2019-07-20 06:58:39 -04:00
|
|
|
.class_name('Person')
|
|
|
|
.inverse_of(:regional_office)
|
2019-07-20 07:46:46 -04:00
|
|
|
.through(:current_supervisor_relationships)
|
2019-07-20 06:58:39 -04:00
|
|
|
.source(:person)
|
|
|
|
.dependent(:restrict_with_exception)
|
|
|
|
end
|
|
|
|
end
|
2018-12-06 17:49:50 -05:00
|
|
|
end
|