2019-04-27 19:24:04 +05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Relationship do
|
|
|
|
subject { create :supporter_relationship }
|
|
|
|
|
2019-07-20 15:07:02 +05:00
|
|
|
describe '#person' do
|
2019-07-20 17:16:48 +05:00
|
|
|
it do
|
|
|
|
is_expected.to belong_to(:person).inverse_of(:all_relationships).required
|
|
|
|
end
|
2019-07-20 15:07:02 +05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#regional_office' do
|
2019-07-20 16:56:26 +05:00
|
|
|
it do
|
|
|
|
is_expected.to \
|
|
|
|
belong_to(:regional_office).inverse_of(:all_relationships).required
|
|
|
|
end
|
2019-07-20 15:07:02 +05:00
|
|
|
end
|
2019-04-28 17:48:51 +05:00
|
|
|
|
2019-07-20 11:22:47 +05:00
|
|
|
describe '#from_date' do
|
|
|
|
it { is_expected.to validate_presence_of :from_date }
|
2019-04-28 18:24:01 +05:00
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.to \
|
2019-07-20 11:22:47 +05:00
|
|
|
validate_uniqueness_of(:from_date)
|
2019-07-20 11:02:32 +05:00
|
|
|
.scoped_to(:person_id)
|
2019-04-28 18:24:01 +05:00
|
|
|
end
|
|
|
|
end
|
2019-06-05 06:37:55 +05:00
|
|
|
|
2019-06-05 07:33:45 +05:00
|
|
|
describe '#status' do
|
|
|
|
it { is_expected.to validate_presence_of :status }
|
|
|
|
end
|
2019-07-20 14:12:58 +05:00
|
|
|
|
|
|
|
describe '#role' do
|
2019-07-22 07:30:58 +05:00
|
|
|
def allow_value(*)
|
|
|
|
super.for :role
|
|
|
|
end
|
|
|
|
|
2019-07-20 14:12:58 +05:00
|
|
|
context 'for supporter relationship' do
|
|
|
|
subject { create :supporter_relationship }
|
|
|
|
|
2019-07-22 07:30:58 +05:00
|
|
|
it { is_expected.to allow_value nil }
|
|
|
|
it { is_expected.not_to allow_value described_class.roles.keys.sample }
|
2019-07-20 14:12:58 +05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for excluded supporter relationship' do
|
|
|
|
subject { create :excluded_supporter_relationship }
|
|
|
|
|
2019-07-22 07:30:58 +05:00
|
|
|
it { is_expected.to allow_value nil }
|
|
|
|
it { is_expected.not_to allow_value described_class.roles.keys.sample }
|
2019-07-20 14:12:58 +05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for excluded member relationship' do
|
|
|
|
subject { create :excluded_member_relationship }
|
|
|
|
|
2019-07-22 07:30:58 +05:00
|
|
|
it { is_expected.to allow_value nil }
|
|
|
|
it { is_expected.not_to allow_value described_class.roles.keys.sample }
|
2019-07-20 14:12:58 +05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for member relationship' do
|
|
|
|
subject { create :member_relationship }
|
|
|
|
|
2019-07-22 07:30:58 +05:00
|
|
|
it { is_expected.to allow_value nil }
|
|
|
|
it { is_expected.to allow_value described_class.roles.keys.sample }
|
2019-07-20 14:12:58 +05:00
|
|
|
end
|
|
|
|
end
|
2019-04-27 19:24:04 +05:00
|
|
|
end
|