1
0
Fork 0

Check person relationship

This commit is contained in:
Alex Kotov 2019-08-15 11:07:58 +05:00
parent 9da7505338
commit ab615c6759
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
2 changed files with 35 additions and 0 deletions

View file

@ -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

View file

@ -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 }