Add association RelationStatus#org_unit_kind
This commit is contained in:
parent
f18c575744
commit
44e1b109b8
|
@ -20,6 +20,9 @@ class OrgUnitKind < ApplicationRecord
|
|||
inverse_of: :kind,
|
||||
foreign_key: :kind_id
|
||||
|
||||
has_many :relation_statuses,
|
||||
inverse_of: :org_unit_kind
|
||||
|
||||
###############
|
||||
# Validations #
|
||||
###############
|
||||
|
|
|
@ -5,6 +5,8 @@ class RelationStatus < ApplicationRecord
|
|||
# Associations #
|
||||
################
|
||||
|
||||
belongs_to :org_unit_kind, inverse_of: :relation_statuses
|
||||
|
||||
has_many :incoming_transitions,
|
||||
class_name: 'RelationTransition',
|
||||
inverse_of: :to_status,
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">
|
||||
<%= RelationStatus.human_attribute_name :org_unit_kind %>
|
||||
</th>
|
||||
<th scope="col">
|
||||
<%= RelationStatus.human_attribute_name :codename %>
|
||||
</th>
|
||||
|
@ -14,7 +17,15 @@
|
|||
<tbody>
|
||||
<% relation_statuses.each do |relation_status| %>
|
||||
<tr>
|
||||
<td scope="row"><%= relation_status.codename %></td>
|
||||
<td scope="row">
|
||||
<% if policy([:staff, relation_status.org_unit_kind]).show? %>
|
||||
<%= link_to relation_status.org_unit_kind.short_name,
|
||||
[:staff, relation_status.org_unit_kind] %>
|
||||
<% else %>
|
||||
<%= relation_status.org_unit_kind.short_name %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td><%= relation_status.codename %></td>
|
||||
<td><%= relation_status.name %></td>
|
||||
<td>
|
||||
<% if policy([:staff, relation_status]).show? %>
|
||||
|
|
|
@ -8,6 +8,16 @@
|
|||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<dl>
|
||||
<dt><%= RelationStatus.human_attribute_name :org_unit_kind %></dt>
|
||||
<dd>
|
||||
<% if policy([:staff, @relation_status.org_unit_kind]).show? %>
|
||||
<%= link_to @relation_status.org_unit_kind.name,
|
||||
[:staff, @relation_status.org_unit_kind] %>
|
||||
<% else %>
|
||||
<%= @relation_status.org_unit_kind.name %>
|
||||
<% end %>
|
||||
</dd>
|
||||
|
||||
<dt><%= RelationStatus.human_attribute_name :codename %></dt>
|
||||
<dd><%= @relation_status.codename %></dd>
|
||||
|
||||
|
|
|
@ -113,6 +113,7 @@ en:
|
|||
text: Text
|
||||
relation_status:
|
||||
id: ID
|
||||
org_unit_kind: Unit type
|
||||
codename: Codename
|
||||
name: Name
|
||||
outgoing_transitions: Outgoing transitions
|
||||
|
|
|
@ -113,6 +113,7 @@ ru:
|
|||
text: Текст
|
||||
relation_status:
|
||||
id: ID
|
||||
org_unit_kind: Тип подразделений
|
||||
codename: Кодовое имя
|
||||
name: Название
|
||||
outgoing_transitions: Исходящие переходы
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddOrgUnitKindToRelationStatuses < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
# rubocop:disable Rails/NotNullColumn
|
||||
|
||||
add_reference :relation_statuses,
|
||||
:org_unit_kind,
|
||||
null: false,
|
||||
foreign_key: true
|
||||
|
||||
# rubocop:enable Rails/NotNullColumn
|
||||
end
|
||||
end
|
|
@ -72,6 +72,7 @@ do |(org_unit_kind, codename, name)|
|
|||
|
||||
RelationStatus.where(codename: codename).first_or_create! \
|
||||
do |new_relation_status|
|
||||
new_relation_status.org_unit_kind = org_unit_kind
|
||||
new_relation_status.name = name
|
||||
end
|
||||
end
|
||||
|
|
|
@ -879,6 +879,7 @@ CREATE TABLE public.relation_statuses (
|
|||
updated_at timestamp(6) without time zone NOT NULL,
|
||||
codename character varying NOT NULL,
|
||||
name character varying NOT NULL,
|
||||
org_unit_kind_id bigint NOT NULL,
|
||||
CONSTRAINT codename CHECK (public.is_codename((codename)::text)),
|
||||
CONSTRAINT name CHECK (public.is_good_small_text((name)::text))
|
||||
);
|
||||
|
@ -1599,6 +1600,13 @@ CREATE UNIQUE INDEX index_relation_statuses_on_codename ON public.relation_statu
|
|||
CREATE UNIQUE INDEX index_relation_statuses_on_name ON public.relation_statuses USING btree (name);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_relation_statuses_on_org_unit_kind_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_relation_statuses_on_org_unit_kind_id ON public.relation_statuses USING btree (org_unit_kind_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_relation_transitions_on_from_status_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -1863,6 +1871,14 @@ ALTER TABLE ONLY public.contacts
|
|||
ADD CONSTRAINT fk_rails_8dffd7a589 FOREIGN KEY (contact_network_id) REFERENCES public.contact_networks(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: relation_statuses fk_rails_8ee81bb15e; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.relation_statuses
|
||||
ADD CONSTRAINT fk_rails_8ee81bb15e FOREIGN KEY (org_unit_kind_id) REFERENCES public.org_unit_kinds(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: person_comments fk_rails_a9c7b4ae11; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -1956,6 +1972,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
|||
('20190930215223'),
|
||||
('20191001022049'),
|
||||
('20191001211809'),
|
||||
('20191002002101');
|
||||
('20191002002101'),
|
||||
('20191002040019');
|
||||
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
FactoryBot.define do
|
||||
factory :some_relation_status, class: RelationStatus do
|
||||
association :org_unit_kind, factory: :some_children_org_unit_kind
|
||||
|
||||
codename { Faker::Internet.unique.username 3..36, %w[_] }
|
||||
name { Faker::Company.unique.name }
|
||||
end
|
||||
|
|
|
@ -45,6 +45,15 @@ RSpec.describe OrgUnitKind do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#relation_statuses' do
|
||||
it do
|
||||
is_expected.to \
|
||||
have_many(:relation_statuses)
|
||||
.inverse_of(:org_unit_kind)
|
||||
.dependent(:restrict_with_exception)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#codename' do
|
||||
def allow_value(*)
|
||||
super.for :codename
|
||||
|
|
|
@ -11,6 +11,15 @@ RSpec.describe RelationStatus do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#org_unit_kind' do
|
||||
it do
|
||||
is_expected.to \
|
||||
belong_to(:org_unit_kind)
|
||||
.inverse_of(:relation_statuses)
|
||||
.required
|
||||
end
|
||||
end
|
||||
|
||||
describe '#incoming_transitions' do
|
||||
it do
|
||||
is_expected.to \
|
||||
|
|
Reference in New Issue