2018-11-30 11:24:05 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2019-06-23 11:54:41 -04:00
|
|
|
RSpec.describe FederalSubject do
|
2019-06-23 11:59:44 -04:00
|
|
|
subject { create :federal_subject }
|
2018-11-30 11:24:05 -05:00
|
|
|
|
2018-12-06 17:49:50 -05:00
|
|
|
it do
|
|
|
|
is_expected.to \
|
|
|
|
have_one(:regional_office)
|
|
|
|
.dependent(:restrict_with_exception)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.not_to validate_presence_of :regional_office }
|
|
|
|
|
2019-03-24 16:52:10 -04:00
|
|
|
it { is_expected.to validate_presence_of :english_name }
|
2019-03-24 17:10:10 -04:00
|
|
|
it { is_expected.to validate_presence_of :native_name }
|
2019-07-19 18:52:14 -04:00
|
|
|
it { is_expected.to validate_presence_of :number }
|
2018-11-30 11:24:05 -05:00
|
|
|
|
2019-03-24 16:52:10 -04:00
|
|
|
it { is_expected.to validate_uniqueness_of :english_name }
|
2019-03-24 17:10:10 -04:00
|
|
|
it { is_expected.to validate_uniqueness_of :native_name }
|
2019-07-19 18:52:14 -04:00
|
|
|
it { is_expected.to validate_uniqueness_of :number }
|
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.to \
|
|
|
|
validate_numericality_of(:number)
|
|
|
|
.only_integer
|
|
|
|
.is_greater_than(0)
|
|
|
|
end
|
2019-03-24 17:37:36 -04:00
|
|
|
|
2019-07-18 15:47:48 -04:00
|
|
|
describe '.order_by_display_name' do
|
|
|
|
let! :federal_subject_1 do
|
|
|
|
create :federal_subject, english_name: '1', native_name: '3'
|
|
|
|
end
|
|
|
|
|
|
|
|
let! :federal_subject_2 do
|
|
|
|
create :federal_subject, english_name: '3', native_name: '5'
|
|
|
|
end
|
|
|
|
|
|
|
|
let! :federal_subject_3 do
|
|
|
|
create :federal_subject, english_name: '4', native_name: '4'
|
|
|
|
end
|
|
|
|
|
|
|
|
let! :federal_subject_4 do
|
|
|
|
create :federal_subject, english_name: '2', native_name: '1'
|
|
|
|
end
|
|
|
|
|
|
|
|
let! :federal_subject_5 do
|
|
|
|
create :federal_subject, english_name: '5', native_name: '2'
|
|
|
|
end
|
|
|
|
|
|
|
|
around do |example|
|
|
|
|
I18n.with_locale locale do
|
|
|
|
example.run
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when locale is "en"' do
|
|
|
|
let(:locale) { :en }
|
|
|
|
|
|
|
|
specify do
|
|
|
|
expect(described_class.order_by_display_name).to eq [
|
|
|
|
federal_subject_1,
|
|
|
|
federal_subject_4,
|
|
|
|
federal_subject_2,
|
|
|
|
federal_subject_3,
|
|
|
|
federal_subject_5,
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
specify do
|
|
|
|
expect(described_class.order_by_display_name(:desc)).to eq [
|
|
|
|
federal_subject_5,
|
|
|
|
federal_subject_3,
|
|
|
|
federal_subject_2,
|
|
|
|
federal_subject_4,
|
|
|
|
federal_subject_1,
|
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when locale is "ru"' do
|
|
|
|
let(:locale) { :ru }
|
|
|
|
|
|
|
|
specify do
|
|
|
|
expect(described_class.order_by_display_name).to eq [
|
|
|
|
federal_subject_4,
|
|
|
|
federal_subject_5,
|
|
|
|
federal_subject_1,
|
|
|
|
federal_subject_3,
|
|
|
|
federal_subject_2,
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
specify do
|
|
|
|
expect(described_class.order_by_display_name(:desc)).to eq [
|
|
|
|
federal_subject_2,
|
|
|
|
federal_subject_3,
|
|
|
|
federal_subject_1,
|
|
|
|
federal_subject_5,
|
|
|
|
federal_subject_4,
|
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-19 22:40:56 -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 17:37:36 -04:00
|
|
|
describe '#display_name' do
|
2019-06-23 11:59:44 -04:00
|
|
|
subject do
|
|
|
|
create :federal_subject, native_name: Faker::Address.unique.state
|
|
|
|
end
|
2019-03-24 17:37:36 -04:00
|
|
|
|
|
|
|
around do |example|
|
|
|
|
I18n.with_locale locale do
|
|
|
|
example.run
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when locale is "en"' do
|
|
|
|
let(:locale) { :en }
|
|
|
|
|
|
|
|
specify do
|
|
|
|
expect(subject.display_name).to eq subject.english_name
|
|
|
|
end
|
|
|
|
|
|
|
|
specify do
|
|
|
|
expect(subject.display_name).not_to eq subject.native_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when locale is "ru"' do
|
|
|
|
let(:locale) { :ru }
|
|
|
|
|
|
|
|
specify do
|
|
|
|
expect(subject.display_name).to eq subject.native_name
|
|
|
|
end
|
|
|
|
|
|
|
|
specify do
|
|
|
|
expect(subject.display_name).not_to eq subject.english_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-11-30 11:24:05 -05:00
|
|
|
end
|