Add column RegionalOffice#name
This commit is contained in:
parent
4c597e2de5
commit
c7fb2bce1e
|
@ -1,6 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class RegionalOffice < ApplicationRecord
|
||||
FORMAT_RE = /\A[^[:space:]]+(.*[^[:space:]]+)?\z/.freeze
|
||||
|
||||
################
|
||||
# Associations #
|
||||
################
|
||||
|
@ -12,4 +14,10 @@ class RegionalOffice < ApplicationRecord
|
|||
###############
|
||||
|
||||
validates :federal_subject, uniqueness: true
|
||||
|
||||
validates :name,
|
||||
presence: true,
|
||||
uniqueness: true,
|
||||
length: { in: 1..255 },
|
||||
format: { with: FORMAT_RE }
|
||||
end
|
||||
|
|
|
@ -203,6 +203,8 @@ private
|
|||
|
||||
t.references :federal_subject,
|
||||
null: false, index: { unique: true }, foreign_key: true
|
||||
|
||||
t.string :name, null: false, index: { unique: true }
|
||||
end
|
||||
|
||||
create_table :people do |t|
|
||||
|
@ -389,6 +391,10 @@ private
|
|||
end
|
||||
|
||||
def change_constraints
|
||||
constraint :regional_offices, :name, <<~SQL
|
||||
is_good_small_text(name)
|
||||
SQL
|
||||
|
||||
constraint :contacts, :value, <<~SQL
|
||||
is_good_small_text(value)
|
||||
SQL
|
||||
|
|
|
@ -667,7 +667,9 @@ CREATE TABLE public.regional_offices (
|
|||
id bigint NOT NULL,
|
||||
created_at timestamp(6) without time zone NOT NULL,
|
||||
updated_at timestamp(6) without time zone NOT NULL,
|
||||
federal_subject_id bigint NOT NULL
|
||||
federal_subject_id bigint NOT NULL,
|
||||
name character varying NOT NULL,
|
||||
CONSTRAINT name CHECK (public.is_good_small_text((name)::text))
|
||||
);
|
||||
|
||||
|
||||
|
@ -1188,6 +1190,13 @@ CREATE INDEX index_person_comments_on_person_id ON public.person_comments USING
|
|||
CREATE UNIQUE INDEX index_regional_offices_on_federal_subject_id ON public.regional_offices USING btree (federal_subject_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_regional_offices_on_name; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE UNIQUE INDEX index_regional_offices_on_name ON public.regional_offices USING btree (name);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_relationships_on_federal_secretary_flag; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
|
|
@ -7,5 +7,7 @@ FactoryBot.define do
|
|||
end
|
||||
|
||||
association :federal_subject
|
||||
|
||||
name { federal_subject&.native_name }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,4 +16,24 @@ RSpec.describe RegionalOffice do
|
|||
|
||||
it { is_expected.to validate_uniqueness_of :federal_subject }
|
||||
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 ' 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
|
||||
|
|
Reference in New Issue