1
0
Fork 0

Add column Contact#send_security_notification

This commit is contained in:
Alex Kotov 2019-09-04 22:44:12 +05:00
parent 1fc802db39
commit 07ae8f16ff
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
5 changed files with 60 additions and 0 deletions

View File

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

View File

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

View File

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

View File

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

View File

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