Check person relationship
This commit is contained in:
parent
9da7505338
commit
ab615c6759
2 changed files with 35 additions and 0 deletions
|
@ -4,6 +4,7 @@ class AcceptAsSupporter
|
|||
include Interactor
|
||||
|
||||
around :wrap_into_transaction
|
||||
before :validate_person
|
||||
before :validate_account
|
||||
after :reload_records
|
||||
|
||||
|
@ -28,6 +29,10 @@ private
|
|||
context.person.reload
|
||||
end
|
||||
|
||||
def validate_person
|
||||
context.fail! unless context.person.current_relationship.nil?
|
||||
end
|
||||
|
||||
def validate_account
|
||||
context.fail! unless context.initiator_account.can_initiate_relationship? \
|
||||
context.regional_office
|
||||
|
|
|
@ -37,6 +37,36 @@ RSpec.describe AcceptAsSupporter do
|
|||
)
|
||||
end
|
||||
|
||||
context 'when person is a supporter' do
|
||||
let!(:person) { create :supporter_person }
|
||||
|
||||
specify { expect(subject).to be_failure }
|
||||
|
||||
specify do
|
||||
expect { subject }.not_to change(Relationship, :count)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when person is a member' do
|
||||
let!(:person) { create :member_person }
|
||||
|
||||
specify { expect(subject).to be_failure }
|
||||
|
||||
specify do
|
||||
expect { subject }.not_to change(Relationship, :count)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when person is excluded' do
|
||||
let!(:person) { create :excluded_person }
|
||||
|
||||
specify { expect(subject).to be_failure }
|
||||
|
||||
specify do
|
||||
expect { subject }.not_to change(Relationship, :count)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when initiator is a federal secretary' do
|
||||
let!(:initiator_account) { create :personal_account }
|
||||
|
||||
|
|
Reference in a new issue