Add column OrgUnit#short_name
This commit is contained in:
parent
5cfd1147db
commit
87437b18aa
5 changed files with 81 additions and 2 deletions
|
@ -23,6 +23,8 @@ class OrgUnit < ApplicationRecord
|
||||||
# Validations #
|
# Validations #
|
||||||
###############
|
###############
|
||||||
|
|
||||||
|
validates :short_name, good_small_text: true, uniqueness: true
|
||||||
|
|
||||||
validates :name, good_small_text: true, uniqueness: true
|
validates :name, good_small_text: true, uniqueness: true
|
||||||
|
|
||||||
validates :parent,
|
validates :parent,
|
||||||
|
|
|
@ -7,7 +7,8 @@ class CreateOrgUnits < ActiveRecord::Migration[6.0]
|
||||||
create_table :org_units do |t|
|
create_table :org_units do |t|
|
||||||
t.timestamps null: false
|
t.timestamps null: false
|
||||||
|
|
||||||
t.string :name, null: false, index: { unique: true }
|
t.string :short_name, null: false, index: { unique: true }
|
||||||
|
t.string :name, null: false, index: { unique: true }
|
||||||
|
|
||||||
t.references :kind,
|
t.references :kind,
|
||||||
null: false,
|
null: false,
|
||||||
|
@ -20,6 +21,10 @@ class CreateOrgUnits < ActiveRecord::Migration[6.0]
|
||||||
foreign_key: { to_table: :org_units }
|
foreign_key: { to_table: :org_units }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
add_constraint :org_units, :short_name, <<~SQL
|
||||||
|
is_good_small_text(short_name)
|
||||||
|
SQL
|
||||||
|
|
||||||
add_constraint :org_units, :name, <<~SQL
|
add_constraint :org_units, :name, <<~SQL
|
||||||
is_good_small_text(name)
|
is_good_small_text(name)
|
||||||
SQL
|
SQL
|
||||||
|
|
|
@ -506,10 +506,12 @@ CREATE TABLE public.org_units (
|
||||||
id bigint NOT NULL,
|
id bigint NOT NULL,
|
||||||
created_at timestamp(6) without time zone NOT NULL,
|
created_at timestamp(6) without time zone NOT NULL,
|
||||||
updated_at timestamp(6) without time zone NOT NULL,
|
updated_at timestamp(6) without time zone NOT NULL,
|
||||||
|
short_name character varying NOT NULL,
|
||||||
name character varying NOT NULL,
|
name character varying NOT NULL,
|
||||||
kind_id bigint NOT NULL,
|
kind_id bigint NOT NULL,
|
||||||
parent_id bigint,
|
parent_id bigint,
|
||||||
CONSTRAINT name CHECK (public.is_good_small_text((name)::text))
|
CONSTRAINT name CHECK (public.is_good_small_text((name)::text)),
|
||||||
|
CONSTRAINT short_name CHECK (public.is_good_small_text((short_name)::text))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
@ -1346,6 +1348,13 @@ CREATE UNIQUE INDEX index_org_units_on_name ON public.org_units USING btree (nam
|
||||||
CREATE INDEX index_org_units_on_parent_id ON public.org_units USING btree (parent_id);
|
CREATE INDEX index_org_units_on_parent_id ON public.org_units USING btree (parent_id);
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Name: index_org_units_on_short_name; Type: INDEX; Schema: public; Owner: -
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE UNIQUE INDEX index_org_units_on_short_name ON public.org_units USING btree (short_name);
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: index_passports_on_federal_subject_id; Type: INDEX; Schema: public; Owner: -
|
-- Name: index_passports_on_federal_subject_id; Type: INDEX; Schema: public; Owner: -
|
||||||
--
|
--
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :some_root_org_unit, class: OrgUnit do
|
factory :some_root_org_unit, class: OrgUnit do
|
||||||
|
short_name { name }
|
||||||
name { Faker::Company.unique.name }
|
name { Faker::Company.unique.name }
|
||||||
|
|
||||||
association :kind, factory: :some_root_org_unit_kind
|
association :kind, factory: :some_root_org_unit_kind
|
||||||
|
|
|
@ -41,4 +41,66 @@ RSpec.describe OrgUnit do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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
|
||||||
end
|
end
|
||||||
|
|
Reference in a new issue