Add column Contact#send_security_notification
This commit is contained in:
parent
1fc802db39
commit
07ae8f16ff
|
@ -27,6 +27,14 @@ class Contact < ApplicationRecord
|
||||||
presence: true,
|
presence: true,
|
||||||
uniqueness: { scope: %i[contact_list_id contact_network_id] }
|
uniqueness: { scope: %i[contact_list_id contact_network_id] }
|
||||||
|
|
||||||
|
validates :send_security_notifications,
|
||||||
|
inclusion: {
|
||||||
|
in: [false],
|
||||||
|
unless: lambda { |record|
|
||||||
|
record.contact_network&.communicable?
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def turn_blanks_into_nils
|
def turn_blanks_into_nils
|
||||||
|
|
|
@ -179,6 +179,9 @@ private
|
||||||
|
|
||||||
t.string :value, null: false
|
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],
|
t.index %i[contact_list_id contact_network_id value],
|
||||||
name: :index_contacts_on_list_id_and_network_id_and_value,
|
name: :index_contacts_on_list_id_and_network_id_and_value,
|
||||||
unique: true
|
unique: true
|
||||||
|
|
|
@ -439,6 +439,7 @@ CREATE TABLE public.contacts (
|
||||||
contact_list_id bigint NOT NULL,
|
contact_list_id bigint NOT NULL,
|
||||||
contact_network_id bigint NOT NULL,
|
contact_network_id bigint NOT NULL,
|
||||||
value character varying 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))
|
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);
|
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: -
|
-- Name: index_federal_subjects_on_english_name; Type: INDEX; Schema: public; Owner: -
|
||||||
--
|
--
|
||||||
|
|
|
@ -7,4 +7,16 @@ FactoryBot.define do
|
||||||
|
|
||||||
value { Faker::Internet.username }
|
value { Faker::Internet.username }
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -47,4 +47,33 @@ RSpec.describe Contact do
|
||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
|
Reference in New Issue