2018-12-01 21:03:19 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Account do
|
2018-12-09 22:36:09 -05:00
|
|
|
subject { create :personal_account }
|
|
|
|
|
2019-07-20 06:07:02 -04:00
|
|
|
pending '#can_access_sidekiq_web_interface?'
|
2018-12-01 21:03:19 -05:00
|
|
|
|
2019-07-20 06:07:02 -04:00
|
|
|
describe '#to_param' do
|
|
|
|
specify do
|
|
|
|
expect(subject.to_param).to eq subject.nickname
|
|
|
|
end
|
|
|
|
end
|
2019-06-26 20:21:37 -04:00
|
|
|
|
2019-07-20 06:07:02 -04:00
|
|
|
describe '#user' do
|
|
|
|
it do
|
|
|
|
is_expected.to \
|
|
|
|
have_one(:user)
|
|
|
|
.dependent(:restrict_with_exception)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.not_to validate_presence_of :user }
|
2019-02-01 22:48:23 -05:00
|
|
|
end
|
|
|
|
|
2019-09-03 09:43:24 -04:00
|
|
|
describe '#sessions' do
|
|
|
|
it do
|
|
|
|
is_expected.to \
|
|
|
|
have_many(:sessions)
|
|
|
|
.dependent(:restrict_with_exception)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-20 06:07:02 -04:00
|
|
|
describe '#person' do
|
|
|
|
it { is_expected.to belong_to(:person).optional }
|
2018-12-04 20:49:26 -05:00
|
|
|
|
2019-07-20 06:07:02 -04:00
|
|
|
it { is_expected.not_to validate_presence_of :person }
|
|
|
|
end
|
2018-12-05 20:55:35 -05:00
|
|
|
|
2019-07-29 01:36:39 -04:00
|
|
|
describe '#contact_list' do
|
2019-06-26 20:43:27 -04:00
|
|
|
def allow_value(*)
|
2019-07-29 01:36:39 -04:00
|
|
|
super.for :contact_list
|
2019-06-26 20:43:27 -04:00
|
|
|
end
|
|
|
|
|
2019-07-29 01:36:39 -04:00
|
|
|
xit { is_expected.to belong_to(:contact_list).required }
|
2019-07-20 06:10:52 -04:00
|
|
|
|
2019-06-26 20:43:27 -04:00
|
|
|
context 'for usual account' do
|
|
|
|
subject { create :usual_account }
|
|
|
|
|
2019-07-29 01:36:39 -04:00
|
|
|
it { is_expected.to allow_value create :empty_contact_list }
|
2019-06-26 20:43:27 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for personal account' do
|
|
|
|
subject { create :personal_account }
|
|
|
|
|
2019-07-29 01:36:39 -04:00
|
|
|
it { is_expected.not_to allow_value create :empty_contact_list }
|
2019-06-26 20:43:27 -04:00
|
|
|
|
2019-07-29 01:36:39 -04:00
|
|
|
it { is_expected.to allow_value subject.person.contact_list }
|
2019-06-26 20:43:27 -04:00
|
|
|
|
|
|
|
specify do
|
2019-07-29 01:36:39 -04:00
|
|
|
expect(subject.contact_list).to eq subject.person.contact_list
|
2019-06-26 20:43:27 -04:00
|
|
|
end
|
2019-07-29 01:26:00 -04:00
|
|
|
|
|
|
|
context 'when it was changed' do
|
|
|
|
before do
|
2019-07-29 01:36:39 -04:00
|
|
|
subject.contact_list = ContactList.new
|
2019-07-29 01:26:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
specify do
|
|
|
|
expect { subject.save validate: false }.to raise_error(
|
|
|
|
ActiveRecord::StatementInvalid,
|
|
|
|
/\APG::RaiseException:\sERROR:\s\s
|
2019-07-29 01:36:39 -04:00
|
|
|
column\s"contact_list_id"\sdoes\snot\smatch\srelated\sperson$/x,
|
2019-07-29 01:26:00 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2019-06-26 20:43:27 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-03 13:16:21 -04:00
|
|
|
describe '#timezone' do
|
|
|
|
def allow_value(*)
|
|
|
|
super.for :timezone
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to validate_presence_of :timezone }
|
|
|
|
|
|
|
|
it { is_expected.to allow_value '00:00:00' }
|
|
|
|
it { is_expected.to allow_value '01:00:00' }
|
|
|
|
it { is_expected.to allow_value '-01:00:00' }
|
|
|
|
it { is_expected.to allow_value '05:00:00' }
|
|
|
|
it { is_expected.to allow_value '-09:00:00' }
|
|
|
|
it { is_expected.to allow_value '12:00:00' }
|
|
|
|
it { is_expected.to allow_value '-12:00:00' }
|
|
|
|
it { is_expected.to allow_value '03:30:00' }
|
|
|
|
it { is_expected.to allow_value '-11:30:00' }
|
|
|
|
it { is_expected.to allow_value '10:45:00' }
|
|
|
|
it { is_expected.to allow_value '-06:15:00' }
|
|
|
|
|
|
|
|
it { is_expected.not_to allow_value '+01:00:00' }
|
|
|
|
end
|
|
|
|
|
2019-03-24 15:27:06 -04:00
|
|
|
describe '#nickname' do
|
2019-01-31 19:47:44 -05:00
|
|
|
def allow_value(*)
|
2019-03-24 15:27:06 -04:00
|
|
|
super.for :nickname
|
2019-01-31 19:47:44 -05:00
|
|
|
end
|
|
|
|
|
2019-03-24 15:27:06 -04:00
|
|
|
it { is_expected.to validate_presence_of :nickname }
|
2019-01-31 19:47:44 -05:00
|
|
|
|
|
|
|
it do
|
2019-03-24 15:27:06 -04:00
|
|
|
is_expected.to validate_length_of(:nickname).is_at_least(3).is_at_most(36)
|
2019-01-31 19:47:44 -05:00
|
|
|
end
|
|
|
|
|
2019-03-24 15:27:06 -04:00
|
|
|
it { is_expected.to validate_uniqueness_of(:nickname).case_insensitive }
|
2019-01-31 19:47:44 -05: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' }
|
|
|
|
|
2019-01-31 20:33:08 -05:00
|
|
|
it do
|
|
|
|
is_expected.not_to \
|
|
|
|
allow_value Faker::Internet.username(3..36, %w[_]).upcase
|
|
|
|
end
|
|
|
|
|
2019-01-31 19:47:44 -05:00
|
|
|
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-02-01 16:46:57 -05:00
|
|
|
describe '#public_name' do
|
|
|
|
def allow_value(*)
|
|
|
|
super.for :public_name
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to allow_value nil }
|
2019-03-24 10:27:18 -04:00
|
|
|
it { is_expected.to allow_value '' }
|
|
|
|
it { is_expected.to allow_value ' ' }
|
2019-02-01 16:46:57 -05: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-03-24 10:27:18 -04:00
|
|
|
|
2019-07-22 17:06:59 -04:00
|
|
|
it { is_expected.to validate_length_of(:public_name).is_at_most(255) }
|
2019-03-24 10:32:07 -04:00
|
|
|
|
2019-03-24 10:27:18 -04:00
|
|
|
context 'when it was set to blank value' do
|
|
|
|
subject { create :personal_account, public_name: ' ' * rand(100) }
|
|
|
|
|
|
|
|
specify do
|
|
|
|
expect(subject.public_name).to eq nil
|
|
|
|
end
|
|
|
|
end
|
2019-03-24 10:42:33 -04:00
|
|
|
|
|
|
|
context 'when it was set to value with leading and trailing spaces' do
|
|
|
|
subject { create :personal_account, public_name: public_name }
|
|
|
|
|
|
|
|
let :public_name do
|
|
|
|
"#{' ' * rand(4)}#{Faker::Name.name}#{' ' * rand(4)}"
|
|
|
|
end
|
|
|
|
|
|
|
|
specify do
|
|
|
|
expect(subject.public_name).to eq public_name.strip
|
|
|
|
end
|
|
|
|
end
|
2019-02-01 16:46:57 -05:00
|
|
|
end
|
|
|
|
|
2019-01-31 23:02:51 -05:00
|
|
|
describe '#biography' do
|
2019-03-24 10:27:18 -04:00
|
|
|
def allow_value(*)
|
|
|
|
super.for :biography
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to allow_value nil }
|
|
|
|
it { is_expected.to allow_value '' }
|
|
|
|
it { is_expected.to allow_value ' ' }
|
|
|
|
|
|
|
|
it { is_expected.to allow_value Faker::Lorem.sentence }
|
|
|
|
|
2019-07-22 17:06:59 -04:00
|
|
|
it { is_expected.to validate_length_of(:biography).is_at_most(10_000) }
|
2019-03-24 10:32:07 -04:00
|
|
|
|
2019-03-24 10:27:18 -04:00
|
|
|
context 'when it was set to blank value' do
|
|
|
|
subject { create :personal_account, biography: ' ' * rand(100) }
|
|
|
|
|
|
|
|
specify do
|
|
|
|
expect(subject.biography).to eq nil
|
|
|
|
end
|
|
|
|
end
|
2019-03-24 10:42:33 -04:00
|
|
|
|
|
|
|
context 'when it was set to value with leading and trailing spaces' do
|
|
|
|
subject { create :personal_account, biography: biography }
|
|
|
|
|
|
|
|
let :biography do
|
|
|
|
"#{' ' * rand(4)}#{Faker::Lorem.sentence}#{' ' * rand(4)}"
|
|
|
|
end
|
|
|
|
|
|
|
|
specify do
|
|
|
|
expect(subject.biography).to eq biography.strip
|
|
|
|
end
|
|
|
|
end
|
2019-01-31 23:02:51 -05:00
|
|
|
end
|
2019-08-15 01:26:56 -04:00
|
|
|
|
|
|
|
describe '#can_initiate_relationship?' do
|
|
|
|
let(:result) { subject.can_initiate_relationship? regional_office }
|
|
|
|
|
|
|
|
let(:regional_office) { create :regional_office }
|
|
|
|
|
|
|
|
context 'for usual account' do
|
|
|
|
subject { create :usual_account }
|
|
|
|
specify { expect(result).to equal false }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for personal account' do
|
|
|
|
subject { create :personal_account }
|
|
|
|
specify { expect(result).to equal false }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for superuser account' do
|
|
|
|
subject { create :superuser_account }
|
|
|
|
specify { expect(result).to equal true }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for federal secretary account' do
|
|
|
|
subject { create :personal_account }
|
|
|
|
before { create :federal_secretary_relationship, person: subject.person }
|
|
|
|
specify { expect(result).to equal true }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for regional secretary account with same region' do
|
|
|
|
subject { create :personal_account }
|
|
|
|
before do
|
|
|
|
create :regional_secretary_relationship,
|
|
|
|
person: subject.person, regional_office: regional_office
|
|
|
|
end
|
|
|
|
specify { expect(result).to equal true }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for regional secretary account with different region' do
|
|
|
|
subject { create :personal_account }
|
|
|
|
before do
|
|
|
|
create :regional_secretary_relationship, person: subject.person
|
|
|
|
end
|
|
|
|
specify { expect(result).to equal false }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for federal manager account' do
|
|
|
|
subject { create :personal_account }
|
|
|
|
before do
|
|
|
|
create :federal_manager_relationship,
|
|
|
|
person: subject.person, regional_office: regional_office
|
|
|
|
end
|
|
|
|
specify { expect(result).to equal false }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for federal supervisor account' do
|
|
|
|
subject { create :personal_account }
|
|
|
|
before do
|
|
|
|
create :federal_supervisor_relationship,
|
|
|
|
person: subject.person, regional_office: regional_office
|
|
|
|
end
|
|
|
|
specify { expect(result).to equal false }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for regional manager account' do
|
|
|
|
subject { create :personal_account }
|
|
|
|
before do
|
|
|
|
create :regional_manager_relationship,
|
|
|
|
person: subject.person, regional_office: regional_office
|
|
|
|
end
|
|
|
|
specify { expect(result).to equal false }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for regional supervisor account' do
|
|
|
|
subject { create :personal_account }
|
|
|
|
before do
|
|
|
|
create :regional_supervisor_relationship,
|
|
|
|
person: subject.person, regional_office: regional_office
|
|
|
|
end
|
|
|
|
specify { expect(result).to equal false }
|
|
|
|
end
|
|
|
|
end
|
2018-12-01 21:03:19 -05:00
|
|
|
end
|