1
0
Fork 0
This repository has been archived on 2023-03-28. You can view files and clone it, but cannot push or open issues or pull requests.
lpr-partynest/spec/models/account_spec.rb

224 lines
5.7 KiB
Ruby
Raw Normal View History

2018-12-02 02:03:19 +00:00
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Account do
2018-12-10 03:36:09 +00:00
subject { create :personal_account }
2019-07-20 10:07:02 +00:00
pending '#can_access_sidekiq_web_interface?'
2018-12-02 02:03:19 +00:00
2019-07-20 10:07:02 +00:00
describe '#to_param' do
specify do
expect(subject.to_param).to eq subject.nickname
end
end
2019-06-27 00:21:37 +00:00
2019-07-20 10:07:02 +00:00
describe '#user' do
it do
is_expected.to \
have_one(:user)
.dependent(:restrict_with_exception)
end
2019-02-02 03:48:23 +00:00
end
2019-09-03 13:43:24 +00:00
describe '#sessions' do
it do
is_expected.to \
have_many(:sessions)
.dependent(:restrict_with_exception)
end
end
2019-07-20 10:07:02 +00:00
describe '#person' do
it { is_expected.to belong_to(:person).optional }
2018-12-05 01:49:26 +00:00
2019-07-20 10:07:02 +00:00
it { is_expected.not_to validate_presence_of :person }
end
describe '#contact_list' do
2019-06-27 00:43:27 +00:00
def allow_value(*)
super.for :contact_list
2019-06-27 00:43:27 +00:00
end
xit { is_expected.to belong_to(:contact_list).required }
2019-07-20 10:10:52 +00:00
2019-06-27 00:43:27 +00:00
context 'for usual account' do
subject { create :usual_account }
it { is_expected.to allow_value create :empty_contact_list }
2019-06-27 00:43:27 +00:00
end
context 'for personal account' do
subject { create :personal_account }
it { is_expected.not_to allow_value create :empty_contact_list }
2019-06-27 00:43:27 +00:00
it { is_expected.to allow_value subject.person.contact_list }
2019-06-27 00:43:27 +00:00
specify do
expect(subject.contact_list).to eq subject.person.contact_list
2019-06-27 00:43:27 +00:00
end
context 'when it was changed' do
before do
subject.contact_list = ContactList.new
end
specify do
expect { subject.save validate: false }.to raise_error(
ActiveRecord::StatementInvalid,
/\APG::RaiseException:\sERROR:\s\s
column\s"contact_list_id"\sdoes\snot\smatch\srelated\sperson$/x,
)
end
end
2019-06-27 00:43:27 +00:00
end
end
2019-09-03 17:16:21 +00: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 19:27:06 +00:00
describe '#nickname' do
2019-02-01 00:47:44 +00:00
def allow_value(*)
2019-03-24 19:27:06 +00:00
super.for :nickname
2019-02-01 00:47:44 +00:00
end
2019-03-24 19:27:06 +00:00
it { is_expected.to validate_presence_of :nickname }
2019-02-01 00:47:44 +00:00
it do
2019-03-24 19:27:06 +00:00
is_expected.to validate_length_of(:nickname).is_at_least(3).is_at_most(36)
2019-02-01 00:47:44 +00:00
end
2019-03-24 19:27:06 +00:00
it { is_expected.to validate_uniqueness_of(:nickname).case_insensitive }
2019-02-01 00:47:44 +00: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
2019-02-01 00:47:44 +00: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 21:46:57 +00:00
describe '#public_name' do
def allow_value(*)
super.for :public_name
end
it { is_expected.to allow_value nil }
it { is_expected.to allow_value '' }
it { is_expected.to allow_value ' ' }
2019-02-01 21:46:57 +00: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-07-22 21:06:59 +00:00
it { is_expected.to validate_length_of(:public_name).is_at_most(255) }
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 14:42:33 +00: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 21:46:57 +00:00
end
2019-02-01 04:02:51 +00:00
describe '#biography' do
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 21:06:59 +00:00
it { is_expected.to validate_length_of(:biography).is_at_most(10_000) }
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 14:42:33 +00: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-02-01 04:02:51 +00:00
end
2019-09-09 22:11:10 +00:00
describe '#restricted?' do
let(:result) { subject.restricted? }
context 'for usual account' do
subject { create :usual_account }
2019-10-09 07:10:07 +00:00
2019-09-09 22:11:10 +00:00
specify { expect(result).to equal true }
end
context 'for personal account' do
subject { create :personal_account }
2019-10-09 07:10:07 +00:00
2019-09-09 22:11:10 +00:00
specify { expect(result).to equal true }
end
context 'for superuser account' do
subject { create :superuser_account }
2019-10-09 07:10:07 +00:00
2019-09-09 22:11:10 +00:00
specify { expect(result).to equal false }
end
end
2018-12-02 02:03:19 +00:00
end