Add column Contact#send_security_notification
This commit is contained in:
parent
1fc802db39
commit
07ae8f16ff
5 changed files with 60 additions and 0 deletions
|
@ -27,6 +27,14 @@ class Contact < ApplicationRecord
|
|||
presence: true,
|
||||
uniqueness: { scope: %i[contact_list_id contact_network_id] }
|
||||
|
||||
validates :send_security_notifications,
|
||||
inclusion: {
|
||||
in: [false],
|
||||
unless: lambda { |record|
|
||||
record.contact_network&.communicable?
|
||||
},
|
||||
}
|
||||
|
||||
private
|
||||
|
||||
def turn_blanks_into_nils
|
||||
|
|
|
@ -179,6 +179,9 @@ private
|
|||
|
||||
t.string :value, null: false
|
||||
|
||||
t.boolean :send_security_notifications,
|
||||
index: true, null: false, default: false
|
||||
|
||||
t.index %i[contact_list_id contact_network_id value],
|
||||
name: :index_contacts_on_list_id_and_network_id_and_value,
|
||||
unique: true
|
||||
|
|
|
@ -439,6 +439,7 @@ CREATE TABLE public.contacts (
|
|||
contact_list_id bigint NOT NULL,
|
||||
contact_network_id bigint NOT NULL,
|
||||
value character varying NOT NULL,
|
||||
send_security_notifications boolean DEFAULT false NOT NULL,
|
||||
CONSTRAINT value CHECK (public.is_good_small_text((value)::text))
|
||||
);
|
||||
|
||||
|
@ -1163,6 +1164,13 @@ CREATE INDEX index_contacts_on_contact_network_id ON public.contacts USING btree
|
|||
CREATE UNIQUE INDEX index_contacts_on_list_id_and_network_id_and_value ON public.contacts USING btree (contact_list_id, contact_network_id, value);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_contacts_on_send_security_notifications; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_contacts_on_send_security_notifications ON public.contacts USING btree (send_security_notifications);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_federal_subjects_on_english_name; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
|
|
@ -7,4 +7,16 @@ FactoryBot.define do
|
|||
|
||||
value { Faker::Internet.username }
|
||||
end
|
||||
|
||||
factory :email_contact, parent: :some_contact do
|
||||
association :contact_network, factory: :email_contact_network
|
||||
|
||||
value { Faker::Internet.email }
|
||||
end
|
||||
|
||||
factory :phone_contact, parent: :some_contact do
|
||||
association :contact_network, factory: :phone_contact_network
|
||||
|
||||
value { Faker::PhoneNumber.cell_phone_with_country_code }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -47,4 +47,33 @@ RSpec.describe Contact do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#send_security_notifications' do
|
||||
def allow_value(*)
|
||||
super.for :send_security_notifications
|
||||
end
|
||||
|
||||
it do
|
||||
is_expected.to \
|
||||
validate_inclusion_of(:send_security_notifications)
|
||||
.in_array([false])
|
||||
end
|
||||
|
||||
context 'for email' do
|
||||
subject { create :email_contact }
|
||||
|
||||
it { is_expected.to allow_value false }
|
||||
it { is_expected.to allow_value true }
|
||||
end
|
||||
|
||||
context 'for phone' do
|
||||
subject { create :phone_contact }
|
||||
|
||||
it do
|
||||
is_expected.to \
|
||||
validate_inclusion_of(:send_security_notifications)
|
||||
.in_array([false])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Reference in a new issue