1
0
Fork 0

Add method ContactNetwork#communicable?

This commit is contained in:
Alex Kotov 2019-09-04 22:24:16 +05:00
parent 2d6a930bb8
commit 1fc802db39
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
3 changed files with 45 additions and 1 deletions

View File

@ -32,4 +32,8 @@ class ContactNetwork < ApplicationRecord
def to_param
codename
end
def communicable?
codename == 'email'
end
end

View File

@ -1,8 +1,26 @@
# frozen_string_literal: true
FactoryBot.define do
factory :contact_network, class: ContactNetwork do
factory :contact_network do
codename { Faker::Internet.unique.username 3..36, %w[_] }
name { Faker::Company.unique.name }
end
factory :email_contact_network, class: ContactNetwork do
initialize_with do
ContactNetwork.find_or_initialize_by codename: 'email'
end
codename { 'email' }
name { 'Email' }
end
factory :phone_contact_network, class: ContactNetwork do
initialize_with do
ContactNetwork.find_or_initialize_by codename: 'phone'
end
codename { 'phone' }
name { 'Phone' }
end
end

View File

@ -75,4 +75,26 @@ RSpec.describe ContactNetwork do
it { is_expected.not_to allow_value "\nFoo" }
it { is_expected.not_to allow_value "Foo\n" }
end
describe '#communicable?' do
specify do
expect(subject.communicable?).to equal false
end
context 'for email' do
subject { create :email_contact_network }
specify do
expect(subject.communicable?).to equal true
end
end
context 'for phone' do
subject { create :phone_contact_network }
specify do
expect(subject.communicable?).to equal false
end
end
end
end