1
0
Fork 0

Add associations

This commit is contained in:
Alex Kotov 2019-08-18 05:59:07 +05:00
parent 4510345b17
commit e75d752bdb
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
2 changed files with 90 additions and 0 deletions

View file

@ -91,6 +91,36 @@ class RegionalOffice < ApplicationRecord
through: :current_regional_supervisor_relationships,
source: :person
has_many :all_accounts,
class_name: 'Account',
through: :all_people,
source: :account
has_many :current_accounts,
class_name: 'Account',
through: :current_people,
source: :account
has_many :current_supporter_accounts,
class_name: 'Account',
through: :current_supporter_people,
source: :account
has_many :current_member_accounts,
class_name: 'Account',
through: :current_member_people,
source: :account
has_many :current_regional_manager_accounts,
class_name: 'Account',
through: :current_regional_manager_people,
source: :account
has_many :current_regional_supervisor_accounts,
class_name: 'Account',
through: :current_regional_supervisor_people,
source: :account
###############
# Validations #
###############

View file

@ -157,4 +157,64 @@ RSpec.describe RegionalOffice do
.dependent(:restrict_with_exception)
end
end
describe '#all_accounts' do
it do
is_expected.to \
have_many(:all_accounts)
.class_name('Account')
.through(:all_people)
.source(:account)
end
end
describe '#current_accounts' do
it do
is_expected.to \
have_many(:current_accounts)
.class_name('Account')
.through(:current_people)
.source(:account)
end
end
describe '#current_supporter_accounts' do
it do
is_expected.to \
have_many(:current_supporter_accounts)
.class_name('Account')
.through(:current_supporter_people)
.source(:account)
end
end
describe '#current_member_accounts' do
it do
is_expected.to \
have_many(:current_member_accounts)
.class_name('Account')
.through(:current_member_people)
.source(:account)
end
end
describe '#current_regional_manager_accounts' do
it do
is_expected.to \
have_many(:current_regional_manager_accounts)
.class_name('Account')
.through(:current_regional_manager_people)
.source(:account)
end
end
describe '#current_regional_supervisor_accounts' do
it do
is_expected.to \
have_many(:current_regional_supervisor_accounts)
.class_name('Account')
.through(:current_regional_supervisor_people)
.source(:account)
end
end
end