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/org_unit_spec.rb

132 lines
3.4 KiB
Ruby
Raw Normal View History

2019-09-30 18:20:45 -04:00
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe OrgUnit do
subject { create :some_children_org_unit }
describe '#kind' do
it do
is_expected.to \
belong_to(:kind)
.class_name('OrgUnitKind')
.inverse_of(:instances)
.required
end
it { is_expected.to validate_presence_of(:kind).with_message(:required) }
end
2019-10-01 21:31:12 -04:00
describe '#parent_unit' do
2019-09-30 18:20:45 -04:00
it do
is_expected.to \
2019-10-01 21:31:12 -04:00
belong_to(:parent_unit)
2019-09-30 18:20:45 -04:00
.class_name('OrgUnit')
2019-10-01 21:31:12 -04:00
.inverse_of(:children_units)
2019-09-30 18:20:45 -04:00
end
context 'when organizational unit type does not require parent' do
subject { create :some_root_org_unit }
it do
2019-10-01 21:31:12 -04:00
is_expected.not_to \
validate_presence_of(:parent_unit)
.with_message(:required)
2019-09-30 18:20:45 -04:00
end
end
context 'when organizational unit type does not require parent' do
subject { create :some_children_org_unit }
it do
2019-10-01 21:31:12 -04:00
is_expected.to \
validate_presence_of(:parent_unit)
.with_message(:required)
2019-09-30 18:20:45 -04:00
end
end
end
2019-09-30 18:32:04 -04:00
2019-10-01 21:31:12 -04:00
describe '#children_units' do
2019-09-30 22:30:04 -04:00
it do
is_expected.to \
2019-10-01 21:31:12 -04:00
have_many(:children_units)
2019-09-30 22:30:04 -04:00
.class_name('OrgUnit')
2019-10-01 21:31:12 -04:00
.inverse_of(:parent_unit)
.with_foreign_key(:parent_unit_id)
2019-09-30 22:30:04 -04:00
.dependent(:restrict_with_exception)
end
end
describe '#all_relationships' do
it do
is_expected.to \
have_many(:all_relationships)
.class_name('Relationship')
.inverse_of(:org_unit)
.dependent(:restrict_with_exception)
end
end
2019-09-30 18:32:04 -04:00
describe '#short_name' do
def allow_value(*)
super.for :short_name
end
it { is_expected.to validate_presence_of :short_name }
it { is_expected.to validate_uniqueness_of :short_name }
it do
is_expected.to \
validate_length_of(:short_name)
.is_at_least(1)
.is_at_most(255)
end
it { is_expected.not_to allow_value nil }
it { is_expected.not_to allow_value '' }
it { is_expected.not_to allow_value ' ' }
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' }
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" }
end
describe '#name' do
def allow_value(*)
super.for :name
end
it { is_expected.to validate_presence_of :name }
it { is_expected.to validate_uniqueness_of :name }
it do
is_expected.to \
validate_length_of(:name)
.is_at_least(1)
.is_at_most(255)
end
it { is_expected.not_to allow_value nil }
it { is_expected.not_to allow_value '' }
it { is_expected.not_to allow_value ' ' }
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' }
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" }
end
2019-09-30 18:20:45 -04:00
end