2019-08-04 17:05:57 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe ContactNetwork do
|
|
|
|
subject { create :contact_network }
|
|
|
|
|
2019-08-17 20:03:18 -04:00
|
|
|
describe '#to_param' do
|
|
|
|
specify do
|
|
|
|
expect(subject.to_param).to eq subject.codename
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-17 20:07:10 -04:00
|
|
|
describe '#contacts' do
|
|
|
|
it do
|
|
|
|
is_expected.to have_many(:contacts).dependent(:restrict_with_exception)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-17 19:51:03 -04:00
|
|
|
describe '#codename' do
|
2019-08-04 17:05:57 -04:00
|
|
|
def allow_value(*)
|
2019-08-17 19:51:03 -04:00
|
|
|
super.for :codename
|
2019-08-04 17:05:57 -04:00
|
|
|
end
|
|
|
|
|
2019-08-17 19:51:03 -04:00
|
|
|
it { is_expected.to validate_presence_of :codename }
|
2019-08-04 17:05:57 -04:00
|
|
|
|
|
|
|
it do
|
2019-08-17 19:51:03 -04:00
|
|
|
is_expected.to validate_length_of(:codename).is_at_least(3).is_at_most(36)
|
2019-08-04 17:05:57 -04:00
|
|
|
end
|
|
|
|
|
2019-08-17 19:51:03 -04:00
|
|
|
it { is_expected.to validate_uniqueness_of(:codename).case_insensitive }
|
2019-08-04 17:05:57 -04:00
|
|
|
|
|
|
|
it { is_expected.not_to allow_value nil }
|
|
|
|
it { is_expected.not_to allow_value '' }
|
|
|
|
it { is_expected.not_to allow_value ' ' * 3 }
|
|
|
|
|
|
|
|
it { is_expected.to allow_value Faker::Internet.username(3..36, %w[_]) }
|
|
|
|
it { is_expected.to allow_value 'foo_bar' }
|
|
|
|
it { is_expected.to allow_value 'foo123' }
|
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.not_to \
|
|
|
|
allow_value Faker::Internet.username(3..36, %w[_]).upcase
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.not_to allow_value Faker::Internet.email }
|
|
|
|
it { is_expected.not_to allow_value '_foo' }
|
|
|
|
it { is_expected.not_to allow_value 'bar_' }
|
|
|
|
it { is_expected.not_to allow_value '1foo' }
|
|
|
|
end
|
|
|
|
|
2019-08-17 20:00:37 -04:00
|
|
|
describe '#name' do
|
2019-08-04 17:05:57 -04:00
|
|
|
def allow_value(*)
|
2019-08-17 20:00:37 -04:00
|
|
|
super.for :name
|
2019-08-04 17:05:57 -04:00
|
|
|
end
|
|
|
|
|
2019-08-18 01:15:03 -04:00
|
|
|
it { is_expected.to validate_presence_of :name }
|
2019-09-30 08:28:08 -04:00
|
|
|
it { is_expected.to validate_uniqueness_of :name }
|
2019-08-04 17:05:57 -04:00
|
|
|
|
2019-08-18 01:15:03 -04:00
|
|
|
it do
|
|
|
|
is_expected.to validate_length_of(:name).is_at_least(1).is_at_most(255)
|
2019-08-04 17:05:57 -04:00
|
|
|
end
|
|
|
|
|
2019-08-18 01:15:03 -04:00
|
|
|
it { is_expected.not_to allow_value nil }
|
|
|
|
it { is_expected.not_to allow_value '' }
|
|
|
|
it { is_expected.not_to allow_value ' ' }
|
2019-08-04 17:05:57 -04:00
|
|
|
|
2019-08-18 01:15:03 -04:00
|
|
|
it { is_expected.to allow_value Faker::Name.name }
|
|
|
|
it { is_expected.to allow_value Faker::Name.first_name }
|
|
|
|
it { is_expected.to allow_value 'Foo Bar' }
|
2019-08-17 20:00:37 -04:00
|
|
|
|
2019-08-18 01:15:03 -04:00
|
|
|
it { is_expected.not_to allow_value ' Foo' }
|
|
|
|
it { is_expected.not_to allow_value 'Foo ' }
|
|
|
|
it { is_expected.not_to allow_value "\tFoo" }
|
|
|
|
it { is_expected.not_to allow_value "Foo\t" }
|
|
|
|
it { is_expected.not_to allow_value "\nFoo" }
|
|
|
|
it { is_expected.not_to allow_value "Foo\n" }
|
2019-08-04 17:05:57 -04:00
|
|
|
end
|
2019-09-04 13:24:16 -04:00
|
|
|
|
|
|
|
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
|
2019-08-04 17:05:57 -04:00
|
|
|
end
|