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

93 lines
2.2 KiB
Ruby
Raw Normal View History

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 }
it { is_expected.to belong_to(:person).optional }
2018-12-01 21:03:19 -05:00
2018-12-01 21:50:10 -05:00
it do
is_expected.to \
have_one(:user)
.dependent(:restrict_with_exception)
end
2018-12-11 19:15:40 -05:00
it do
is_expected.to \
have_many(:account_telegram_contacts)
.dependent(:restrict_with_exception)
end
it do
is_expected.to \
2018-12-13 00:36:00 -05:00
have_one(:own_membership_app)
.class_name('MembershipApp')
.dependent(:restrict_with_exception)
end
2018-12-01 21:28:34 -05:00
it do
is_expected.to \
have_many(:passport_confirmations)
.dependent(:restrict_with_exception)
end
2018-12-01 21:50:10 -05:00
2018-12-09 22:36:09 -05:00
it { is_expected.not_to validate_presence_of :person }
2018-12-01 21:50:10 -05:00
it { is_expected.not_to validate_presence_of :user }
2018-12-04 20:49:26 -05:00
pending '.guests'
pending '#guest?'
pending '#can_access_sidekiq_web_interface?'
2019-01-31 19:47:44 -05:00
describe '#username' do
def allow_value(*)
super.for :username
end
it { is_expected.to validate_presence_of :username }
it do
is_expected.to validate_length_of(:username).is_at_least(3).is_at_most(36)
end
it { is_expected.to validate_uniqueness_of(:username).case_insensitive }
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-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
describe '#add_role' do
context 'to guest account' do
subject { create :guest_account }
let(:result) { subject.add_role :superuser }
specify do
expect { result }.to \
raise_error RuntimeError, 'can not add role to guest account'
end
specify do
expect { result rescue nil }.not_to(
change { subject.roles.reload.count },
)
end
end
end
2018-12-01 21:03:19 -05:00
end