Rename column ContactNetwork#public_name to #name
This commit is contained in:
parent
cc9c846cc9
commit
62a8ec4643
|
@ -20,17 +20,17 @@ class ContactNetwork < ApplicationRecord
|
||||||
format: CODENAME_RE,
|
format: CODENAME_RE,
|
||||||
uniqueness: { case_sensitive: false }
|
uniqueness: { case_sensitive: false }
|
||||||
|
|
||||||
validates :public_name, allow_nil: true, length: { in: 1..255 }
|
validates :name, allow_nil: true, length: { in: 1..255 }
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def turn_blanks_into_nils
|
def turn_blanks_into_nils
|
||||||
self.codename = nil if codename.blank?
|
self.codename = nil if codename.blank?
|
||||||
self.public_name = nil if public_name.blank?
|
self.name = nil if name.blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
def strip_extra_spaces
|
def strip_extra_spaces
|
||||||
self.codename = codename&.strip
|
self.codename = codename&.strip
|
||||||
self.public_name = public_name&.strip
|
self.name = name&.strip
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
<%= ContactNetwork.human_attribute_name :codename %>
|
<%= ContactNetwork.human_attribute_name :codename %>
|
||||||
</th>
|
</th>
|
||||||
<th scope="col">
|
<th scope="col">
|
||||||
<%= ContactNetwork.human_attribute_name :public_name %>
|
<%= ContactNetwork.human_attribute_name :name %>
|
||||||
</th>
|
</th>
|
||||||
<th scope="col"></th>
|
<th scope="col"></th>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -21,7 +21,7 @@
|
||||||
<% @contact_networks.each do |contact_network| %>
|
<% @contact_networks.each do |contact_network| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td scope="row"><%= contact_network.codename %></td>
|
<td scope="row"><%= contact_network.codename %></td>
|
||||||
<td><%= contact_network.public_name %></td>
|
<td><%= contact_network.name %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
@ -39,7 +39,7 @@ en:
|
||||||
contact_network:
|
contact_network:
|
||||||
id: ID
|
id: ID
|
||||||
codename: Codename
|
codename: Codename
|
||||||
public_name: Public name
|
name: Name
|
||||||
federal_subject:
|
federal_subject:
|
||||||
id: ID
|
id: ID
|
||||||
regional_office: Regional department
|
regional_office: Regional department
|
||||||
|
|
|
@ -39,7 +39,7 @@ ru:
|
||||||
contact_network:
|
contact_network:
|
||||||
id: ID
|
id: ID
|
||||||
codename: Кодовое имя
|
codename: Кодовое имя
|
||||||
public_name: Публичное имя
|
name: Название
|
||||||
federal_subject:
|
federal_subject:
|
||||||
id: ID
|
id: ID
|
||||||
regional_office: Региональное отделение
|
regional_office: Региональное отделение
|
||||||
|
|
|
@ -171,7 +171,7 @@ private
|
||||||
t.timestamps null: false
|
t.timestamps null: false
|
||||||
|
|
||||||
t.string :codename, null: false, index: { unique: true }
|
t.string :codename, null: false, index: { unique: true }
|
||||||
t.string :public_name, null: false, index: { unique: true }
|
t.string :name, null: false, index: { unique: true }
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table :contact_lists do |t|
|
create_table :contact_lists do |t|
|
||||||
|
@ -397,8 +397,8 @@ private
|
||||||
is_codename(codename)
|
is_codename(codename)
|
||||||
SQL
|
SQL
|
||||||
|
|
||||||
constraint :contact_networks, :public_name, <<~SQL
|
constraint :contact_networks, :name, <<~SQL
|
||||||
is_good_small_text(public_name)
|
is_good_small_text(name)
|
||||||
SQL
|
SQL
|
||||||
|
|
||||||
constraint :relationships, :role, <<~SQL
|
constraint :relationships, :role, <<~SQL
|
||||||
|
|
|
@ -25,17 +25,14 @@ CSV.foreach(
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
CSV.foreach(
|
CSV.foreach contact_networks_filename, col_sep: '|' do |(id, codename, name)|
|
||||||
contact_networks_filename,
|
|
||||||
col_sep: '|',
|
|
||||||
) do |(id, codename, public_name)|
|
|
||||||
id = Integer(id.strip)
|
id = Integer(id.strip)
|
||||||
codename.strip!
|
codename.strip!
|
||||||
public_name.strip!
|
name.strip!
|
||||||
|
|
||||||
ContactNetwork.where(id: id).first_or_create! do |new_contact_network|
|
ContactNetwork.where(id: id).first_or_create! do |new_contact_network|
|
||||||
new_contact_network.codename = codename
|
new_contact_network.codename = codename
|
||||||
new_contact_network.public_name = public_name
|
new_contact_network.name = name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -417,9 +417,9 @@ CREATE TABLE public.contact_networks (
|
||||||
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,
|
||||||
codename character varying NOT NULL,
|
codename character varying NOT NULL,
|
||||||
public_name character varying NOT NULL,
|
name character varying NOT NULL,
|
||||||
CONSTRAINT codename CHECK (public.is_codename((codename)::text)),
|
CONSTRAINT codename CHECK (public.is_codename((codename)::text)),
|
||||||
CONSTRAINT public_name CHECK (public.is_good_small_text((public_name)::text))
|
CONSTRAINT name CHECK (public.is_good_small_text((name)::text))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
@ -1105,10 +1105,10 @@ CREATE UNIQUE INDEX index_contact_networks_on_codename ON public.contact_network
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: index_contact_networks_on_public_name; Type: INDEX; Schema: public; Owner: -
|
-- Name: index_contact_networks_on_name; Type: INDEX; Schema: public; Owner: -
|
||||||
--
|
--
|
||||||
|
|
||||||
CREATE UNIQUE INDEX index_contact_networks_on_public_name ON public.contact_networks USING btree (public_name);
|
CREATE UNIQUE INDEX index_contact_networks_on_name ON public.contact_networks USING btree (name);
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
|
|
|
@ -3,6 +3,6 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :contact_network, class: ContactNetwork do
|
factory :contact_network, class: ContactNetwork do
|
||||||
codename { Faker::Internet.username 3..36, %w[_] }
|
codename { Faker::Internet.username 3..36, %w[_] }
|
||||||
public_name { Faker::Company.unique.name }
|
name { Faker::Company.unique.name }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -37,9 +37,9 @@ RSpec.describe ContactNetwork do
|
||||||
it { is_expected.not_to allow_value '1foo' }
|
it { is_expected.not_to allow_value '1foo' }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#public_name' do
|
describe '#name' do
|
||||||
def allow_value(*)
|
def allow_value(*)
|
||||||
super.for :public_name
|
super.for :name
|
||||||
end
|
end
|
||||||
|
|
||||||
it { is_expected.to allow_value nil }
|
it { is_expected.to allow_value nil }
|
||||||
|
@ -50,25 +50,29 @@ RSpec.describe ContactNetwork do
|
||||||
it { is_expected.to allow_value Faker::Name.first_name }
|
it { is_expected.to allow_value Faker::Name.first_name }
|
||||||
it { is_expected.to allow_value 'Foo Bar' }
|
it { is_expected.to allow_value 'Foo Bar' }
|
||||||
|
|
||||||
it { is_expected.to validate_length_of(:public_name).is_at_most(255) }
|
it { is_expected.to validate_length_of(:name).is_at_most(255) }
|
||||||
|
|
||||||
context 'when it was set to blank value' do
|
context 'when it was set to blank value' do
|
||||||
subject { create :personal_account, public_name: ' ' * rand(100) }
|
subject { build :contact_network, name: ' ' * rand(100) }
|
||||||
|
|
||||||
|
before { subject.validate }
|
||||||
|
|
||||||
specify do
|
specify do
|
||||||
expect(subject.public_name).to eq nil
|
expect(subject.name).to eq nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when it was set to value with leading and trailing spaces' do
|
context 'when it was set to value with leading and trailing spaces' do
|
||||||
subject { create :personal_account, public_name: public_name }
|
subject { create :contact_network, name: name }
|
||||||
|
|
||||||
let :public_name do
|
let :name do
|
||||||
"#{' ' * rand(4)}#{Faker::Name.name}#{' ' * rand(4)}"
|
"#{' ' * rand(4)}#{Faker::Name.name}#{' ' * rand(4)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
before { subject.validate }
|
||||||
|
|
||||||
specify do
|
specify do
|
||||||
expect(subject.public_name).to eq public_name.strip
|
expect(subject.name).to eq name.strip
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Reference in New Issue