1
0
Fork 0

Remove model RegionalOffice

This commit is contained in:
Alex Kotov 2019-10-01 02:16:11 +05:00
parent 9128f1d93c
commit 9d940fcc48
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
21 changed files with 67 additions and 297 deletions

View File

@ -1,16 +0,0 @@
# frozen_string_literal: true
module RegionalOfficesHelper
def regional_office_link_or_none(regional_office)
if regional_office.nil?
none
elsif policy(regional_office.federal_subject).show?
link_to regional_office.federal_subject.display_name,
regional_office.federal_subject
else
regional_office.federal_subject.display_name
end
end
alias staff_regional_office_link_or_none regional_office_link_or_none
end

View File

@ -13,12 +13,6 @@ class FederalSubject < ApplicationRecord
end
}
################
# Associations #
################
has_one :regional_office
###############
# Validations #
###############

View File

@ -1,17 +0,0 @@
# frozen_string_literal: true
class RegionalOffice < ApplicationRecord
################
# Associations #
################
belongs_to :federal_subject
###############
# Validations #
###############
validates :federal_subject, uniqueness: true
validates :name, good_small_text: true, uniqueness: true
end

View File

@ -9,8 +9,6 @@ class Relationship < ApplicationRecord
belongs_to :person, inverse_of: :all_relationships
belongs_to :regional_office
###############
# Validations #
###############

View File

@ -21,16 +21,6 @@
</div>
<% end %>
<div class="mt-2">
<% if @account.person&.current_relationship&.regional_office %>
<div>
<i class="fas fa-map-marker-alt fa-fw"></i>
<%= regional_office_link_or_none \
@account.person.current_relationship.regional_office %>
</div>
<% end %>
</div>
<hr/>
<% if @account.biography %>

View File

@ -13,9 +13,6 @@
<th scope="col">
<%= FederalSubject.human_attribute_name :timezone %>
</th>
<th scope="col">
<%= FederalSubject.human_attribute_name :regional_office %>
</th>
<th scope="col"></th>
</tr>
</thead>
@ -27,13 +24,6 @@
<td><%= truncate federal_subject.display_name, length: 25 %></td>
<td><%= truncate federal_subject.centre, length: 15 %></td>
<td><%= federal_subject.timezone %></td>
<td>
<% if federal_subject.regional_office.nil? %>
<%= translate :no %>
<% else %>
<%= translate :yes %>
<% end %>
</td>
<td>
<% if policy(federal_subject).show? %>
<%= open_action federal_subject %>

View File

@ -21,14 +21,5 @@
<dt><%= FederalSubject.human_attribute_name :timezone %></dt>
<dd><%= @federal_subject.timezone %></dd>
<dt><%= FederalSubject.human_attribute_name :regional_office %></dt>
<dd>
<% if @federal_subject.regional_office.nil? %>
<%= translate :no %>
<% else %>
<%= translate :yes %>
<% end %>
</dd>
</dl>
</div>

View File

@ -7,9 +7,6 @@
<th scope="col">
<%= Relationship.human_attribute_name :from_date %>
</th>
<th scope="col">
<%= Relationship.human_attribute_name :regional_office %>
</th>
<th scope="col"></th>
</tr>
</thead>
@ -19,10 +16,6 @@
<tr>
<td scope="row"><%= relationship.id %></td>
<td><%= relationship_from_date_or_none relationship %></td>
<td>
<%= staff_regional_office_link_or_none \
relationship.regional_office %>
</td>
<td></td>
</tr>
<% end %>

View File

@ -62,12 +62,6 @@
<dd>
<%= relationship_from_date_or_none @person.current_relationship %>
</dd>
<dt><%= Relationship.human_attribute_name :regional_office %></dt>
<dd>
<%= staff_regional_office_link_or_none \
@person.current_relationship&.regional_office %>
</dd>
</dl>
</div>
</div>

View File

@ -27,9 +27,6 @@ en:
person_comment:
one: Comment
many: Comments
regional_office:
one: Regional office
many: Regional offices
relation_status:
one: Relation status
few: Relation statuses
@ -65,7 +62,6 @@ en:
name: Name
federal_subject:
id: ID
regional_office: Regional department
english_name: Name
native_name: Name
display_name: Name
@ -105,8 +101,6 @@ en:
id: ID
attachment: Attachment
text: Text
regional_office:
id: ID
relation_status:
id: ID
codename: Codename
@ -114,7 +108,6 @@ en:
transitions: Transitions
relationship:
id: ID
regional_office: Regional department
from_date: From date
session:
id: ID

View File

@ -27,9 +27,6 @@ ru:
person_comment:
one: Комментарий
many: Комментарии
regional_office:
one: Региональное отделение
many: Региональные отделения
relation_status:
one: Статус отношения
few: Статусы отношения
@ -65,7 +62,6 @@ ru:
name: Название
federal_subject:
id: ID
regional_office: Региональное отделение
english_name: Название
native_name: Название
display_name: Название
@ -105,8 +101,6 @@ ru:
id: ID
attachment: Приложение
text: Текст
regional_office:
id: ID
relation_status:
id: ID
codename: Кодовое имя
@ -114,7 +108,6 @@ ru:
transitions: Переходы
relationship:
id: ID
regional_office: Региональное отделение
from_date: Дата начала
session:
id: ID

View File

@ -0,0 +1,28 @@
# frozen_string_literal: true
class RemoveRegionalOffices < ActiveRecord::Migration[6.0]
include Partynest::Migration
def change
remove_reference :relationships,
:regional_office,
null: false,
index: true,
foreign_key: true
drop_constraint :regional_offices, :name, <<~SQL
is_good_small_text(name)
SQL
drop_table :regional_offices do |t|
t.timestamps null: false
t.references :federal_subject,
null: false,
index: { unique: true },
foreign_key: true
t.string :name, null: false, index: { unique: true }
end
end
end

View File

@ -643,39 +643,6 @@ CREATE SEQUENCE public.person_comments_id_seq
ALTER SEQUENCE public.person_comments_id_seq OWNED BY public.person_comments.id;
--
-- Name: regional_offices; Type: TABLE; Schema: public; Owner: -
--
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,
name character varying NOT NULL,
CONSTRAINT name CHECK (public.is_good_small_text((name)::text))
);
--
-- Name: regional_offices_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.regional_offices_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: regional_offices_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.regional_offices_id_seq OWNED BY public.regional_offices.id;
--
-- Name: relation_statuses; Type: TABLE; Schema: public; Owner: -
--
@ -754,7 +721,6 @@ CREATE TABLE public.relationships (
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL,
person_id bigint NOT NULL,
regional_office_id bigint NOT NULL,
from_date date NOT NULL,
status_id bigint NOT NULL
);
@ -983,13 +949,6 @@ ALTER TABLE ONLY public.people ALTER COLUMN id SET DEFAULT nextval('public.peopl
ALTER TABLE ONLY public.person_comments ALTER COLUMN id SET DEFAULT nextval('public.person_comments_id_seq'::regclass);
--
-- Name: regional_offices id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.regional_offices ALTER COLUMN id SET DEFAULT nextval('public.regional_offices_id_seq'::regclass);
--
-- Name: relation_statuses id; Type: DEFAULT; Schema: public; Owner: -
--
@ -1128,14 +1087,6 @@ ALTER TABLE ONLY public.person_comments
ADD CONSTRAINT person_comments_pkey PRIMARY KEY (id);
--
-- Name: regional_offices regional_offices_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.regional_offices
ADD CONSTRAINT regional_offices_pkey PRIMARY KEY (id);
--
-- Name: relation_statuses relation_statuses_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
@ -1360,20 +1311,6 @@ CREATE INDEX index_person_comments_on_account_id ON public.person_comments USING
CREATE INDEX index_person_comments_on_person_id ON public.person_comments USING btree (person_id);
--
-- Name: index_regional_offices_on_federal_subject_id; Type: INDEX; Schema: public; Owner: -
--
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_relation_statuses_on_codename; Type: INDEX; Schema: public; Owner: -
--
@ -1430,13 +1367,6 @@ CREATE INDEX index_relationships_on_from_date ON public.relationships USING btre
CREATE UNIQUE INDEX index_relationships_on_person_id_and_from_date ON public.relationships USING btree (person_id, from_date);
--
-- Name: index_relationships_on_regional_office_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_relationships_on_regional_office_id ON public.relationships USING btree (regional_office_id);
--
-- Name: index_relationships_on_status_id; Type: INDEX; Schema: public; Owner: -
--
@ -1521,14 +1451,6 @@ CREATE TRIGGER ensure_contact_list_id_remains_unchanged BEFORE UPDATE OF contact
CREATE TRIGGER ensure_superuser_has_related_user BEFORE INSERT OR UPDATE ON public.accounts FOR EACH ROW EXECUTE PROCEDURE public.ensure_superuser_has_related_user();
--
-- Name: relationships fk_rails_100235139c; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.relationships
ADD CONSTRAINT fk_rails_100235139c FOREIGN KEY (regional_office_id) REFERENCES public.regional_offices(id);
--
-- Name: people fk_rails_4f02f930eb; Type: FK CONSTRAINT; Schema: public; Owner: -
--
@ -1585,14 +1507,6 @@ ALTER TABLE ONLY public.accounts
ADD CONSTRAINT fk_rails_77a360a20e FOREIGN KEY (contact_list_id) REFERENCES public.contact_lists(id);
--
-- Name: regional_offices fk_rails_7a6d5fdd9a; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.regional_offices
ADD CONSTRAINT fk_rails_7a6d5fdd9a FOREIGN KEY (federal_subject_id) REFERENCES public.federal_subjects(id);
--
-- Name: relationships fk_rails_87a7339f1f; Type: FK CONSTRAINT; Schema: public; Owner: -
--
@ -1689,6 +1603,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20190928171705'),
('20190929131544'),
('20190930154031'),
('20190930205337');
('20190930205337'),
('20190930210852');

View File

@ -3,7 +3,7 @@
FactoryBot.define do
factory :initial_person, class: Person do
transient do
regional_office { create :regional_office }
regional_office { nil }
end
association :contact_list, factory: :empty_contact_list
@ -17,66 +17,66 @@ FactoryBot.define do
end
factory :supporter_person, parent: :initial_person do
after :create do |person, evaluator|
after :create do |person, _evaluator|
create :supporter_relationship,
person: person,
regional_office: evaluator.regional_office
person: person # ,
# regional_office: evaluator.regional_office
end
end
factory :member_person, parent: :initial_person do
after :create do |person, evaluator|
after :create do |person, _evaluator|
create :member_relationship,
person: person,
regional_office: evaluator.regional_office
person: person # ,
# regional_office: evaluator.regional_office
end
end
factory :excluded_person, parent: :initial_person do
after :create do |person, evaluator|
after :create do |person, _evaluator|
create :excluded_relationship,
person: person,
regional_office: evaluator.regional_office
person: person # ,
# regional_office: evaluator.regional_office
end
end
factory :federal_manager_person, parent: :initial_person do
after :create do |person, evaluator|
after :create do |person, _evaluator|
create :federal_manager_relationship,
person: person,
regional_office: evaluator.regional_office
person: person # ,
# regional_office: evaluator.regional_office
end
end
factory :federal_supervisor_person, parent: :initial_person do
after :create do |person, evaluator|
after :create do |person, _evaluator|
create :federal_supervisor_relationship,
person: person,
regional_office: evaluator.regional_office
person: person # ,
# regional_office: evaluator.regional_office
end
end
factory :regional_manager_person, parent: :initial_person do
after :create do |person, evaluator|
after :create do |person, _evaluator|
create :regional_manager_relationship,
person: person,
regional_office: evaluator.regional_office
person: person # ,
# regional_office: evaluator.regional_office
end
end
factory :regional_supervisor_person, parent: :initial_person do
after :create do |person, evaluator|
after :create do |person, _evaluator|
create :regional_supervisor_relationship,
person: person,
regional_office: evaluator.regional_office
person: person # ,
# regional_office: evaluator.regional_office
end
end
factory :regional_secretary_person, parent: :initial_person do
after :create do |person, evaluator|
after :create do |person, _evaluator|
create :regional_secretary_relationship,
person: person,
regional_office: evaluator.regional_office
person: person # ,
# regional_office: evaluator.regional_office
end
end
end

View File

@ -1,13 +0,0 @@
# frozen_string_literal: true
FactoryBot.define do
factory :regional_office do
initialize_with do
RegionalOffice.find_or_initialize_by federal_subject: federal_subject
end
association :federal_subject
name { federal_subject&.native_name }
end
end

View File

@ -4,7 +4,6 @@ FactoryBot.define do
factory :supporter_relationship, class: Relationship do
association :status, factory: :some_relation_status
association :person, factory: :initial_person
association :regional_office
sequence :from_date do |n|
Date.new rand((10 * n)...(11 * n)), rand(1..12), rand(1..28)

View File

@ -21,10 +21,10 @@ end
When 'there is a supporter account with the following data:' do |table|
options = table.raw.map { |(k, v)| [k.to_sym, v] }.to_h
federal_subject =
create :federal_subject, english_name: options[:federal_subject]
regional_office = create :regional_office, federal_subject: federal_subject
person = create :supporter_person, regional_office: regional_office
# federal_subject =
# create :federal_subject, english_name: options[:federal_subject]
# regional_office = create :regional_office, federal_subject: federal_subject
person = create :supporter_person # , regional_office: regional_office
create :personal_account,
nickname: options[:nickname],
@ -36,10 +36,10 @@ end
When 'there is an excluded member account with the following data:' do |table|
options = table.raw.map { |(k, v)| [k.to_sym, v] }.to_h
federal_subject =
create :federal_subject, english_name: options[:federal_subject]
regional_office = create :regional_office, federal_subject: federal_subject
person = create :excluded_person, regional_office: regional_office
# federal_subject =
# create :federal_subject, english_name: options[:federal_subject]
# regional_office = create :regional_office, federal_subject: federal_subject
person = create :excluded_person # , regional_office: regional_office
create :personal_account,
nickname: options[:nickname],
@ -53,10 +53,10 @@ When 'there is a member account with the following data:' do |table|
person_factory = options[:factory].presence || :member_person
federal_subject =
create :federal_subject, english_name: options[:federal_subject]
regional_office = create :regional_office, federal_subject: federal_subject
person = create person_factory, regional_office: regional_office
# federal_subject =
# create :federal_subject, english_name: options[:federal_subject]
# regional_office = create :regional_office, federal_subject: federal_subject
person = create person_factory # , regional_office: regional_office
create :personal_account,
nickname: options[:nickname],

View File

@ -1,7 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe RegionalOfficesHelper do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@ -5,16 +5,6 @@ require 'rails_helper'
RSpec.describe FederalSubject do
subject { create :federal_subject }
describe '#regional_office' do
it do
is_expected.to \
have_one(:regional_office)
.dependent(:restrict_with_exception)
end
it { is_expected.not_to validate_presence_of :regional_office }
end
describe '#to_param' do
specify do
expect(subject.to_param).to be_instance_of String

View File

@ -1,39 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe RegionalOffice do
subject { create :regional_office }
describe '#federal_subject' do
it { is_expected.to belong_to :federal_subject }
it do
is_expected.to \
validate_presence_of(:federal_subject)
.with_message(:required)
end
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

View File

@ -17,12 +17,6 @@ RSpec.describe Relationship do
end
end
describe '#regional_office' do
it do
is_expected.to belong_to(:regional_office).required
end
end
describe '#from_date' do
it { is_expected.to validate_presence_of :from_date }