From 9d940fcc484d6731fa5a0a8155dc8f4c8eee22c1 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Tue, 1 Oct 2019 02:16:11 +0500 Subject: [PATCH] Remove model RegionalOffice --- app/helpers/regional_offices_helper.rb | 16 ---- app/models/federal_subject.rb | 6 -- app/models/regional_office.rb | 17 ---- app/models/relationship.rb | 2 - app/views/accounts/show.html.erb | 10 --- app/views/federal_subjects/_table.html.erb | 10 --- app/views/federal_subjects/show.html.erb | 9 -- .../people/relationships/_table.html.erb | 7 -- app/views/staffs/people/show.html.erb | 6 -- config/locales/activerecord/en.yml | 7 -- config/locales/activerecord/ru.yml | 7 -- .../20190930210852_remove_regional_offices.rb | 28 ++++++ db/structure.sql | 89 +------------------ factories/people.rb | 50 +++++------ factories/regional_offices.rb | 13 --- factories/relationships.rb | 1 - features/step_definitions/account.rb | 24 ++--- spec/helpers/regional_offices_helper_spec.rb | 7 -- spec/models/federal_subject_spec.rb | 10 --- spec/models/regional_office_spec.rb | 39 -------- spec/models/relationship_spec.rb | 6 -- 21 files changed, 67 insertions(+), 297 deletions(-) delete mode 100644 app/helpers/regional_offices_helper.rb delete mode 100644 app/models/regional_office.rb create mode 100644 db/migrate/20190930210852_remove_regional_offices.rb delete mode 100644 factories/regional_offices.rb delete mode 100644 spec/helpers/regional_offices_helper_spec.rb delete mode 100644 spec/models/regional_office_spec.rb diff --git a/app/helpers/regional_offices_helper.rb b/app/helpers/regional_offices_helper.rb deleted file mode 100644 index 4886cd6..0000000 --- a/app/helpers/regional_offices_helper.rb +++ /dev/null @@ -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 diff --git a/app/models/federal_subject.rb b/app/models/federal_subject.rb index 01007d0..d25869a 100644 --- a/app/models/federal_subject.rb +++ b/app/models/federal_subject.rb @@ -13,12 +13,6 @@ class FederalSubject < ApplicationRecord end } - ################ - # Associations # - ################ - - has_one :regional_office - ############### # Validations # ############### diff --git a/app/models/regional_office.rb b/app/models/regional_office.rb deleted file mode 100644 index eecd136..0000000 --- a/app/models/regional_office.rb +++ /dev/null @@ -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 diff --git a/app/models/relationship.rb b/app/models/relationship.rb index f9c3bc0..8d582bf 100644 --- a/app/models/relationship.rb +++ b/app/models/relationship.rb @@ -9,8 +9,6 @@ class Relationship < ApplicationRecord belongs_to :person, inverse_of: :all_relationships - belongs_to :regional_office - ############### # Validations # ############### diff --git a/app/views/accounts/show.html.erb b/app/views/accounts/show.html.erb index aeda1f7..b0fef29 100644 --- a/app/views/accounts/show.html.erb +++ b/app/views/accounts/show.html.erb @@ -21,16 +21,6 @@ <% end %> -
- <% if @account.person&.current_relationship&.regional_office %> -
- - <%= regional_office_link_or_none \ - @account.person.current_relationship.regional_office %> -
- <% end %> -
-
<% if @account.biography %> diff --git a/app/views/federal_subjects/_table.html.erb b/app/views/federal_subjects/_table.html.erb index 4a5405c..23e1b59 100644 --- a/app/views/federal_subjects/_table.html.erb +++ b/app/views/federal_subjects/_table.html.erb @@ -13,9 +13,6 @@ <%= FederalSubject.human_attribute_name :timezone %> - - <%= FederalSubject.human_attribute_name :regional_office %> - @@ -27,13 +24,6 @@ <%= truncate federal_subject.display_name, length: 25 %> <%= truncate federal_subject.centre, length: 15 %> <%= federal_subject.timezone %> - - <% if federal_subject.regional_office.nil? %> - <%= translate :no %> - <% else %> - <%= translate :yes %> - <% end %> - <% if policy(federal_subject).show? %> <%= open_action federal_subject %> diff --git a/app/views/federal_subjects/show.html.erb b/app/views/federal_subjects/show.html.erb index 7caf22b..07d2100 100644 --- a/app/views/federal_subjects/show.html.erb +++ b/app/views/federal_subjects/show.html.erb @@ -21,14 +21,5 @@
<%= FederalSubject.human_attribute_name :timezone %>
<%= @federal_subject.timezone %>
- -
<%= FederalSubject.human_attribute_name :regional_office %>
-
- <% if @federal_subject.regional_office.nil? %> - <%= translate :no %> - <% else %> - <%= translate :yes %> - <% end %> -
diff --git a/app/views/staffs/people/relationships/_table.html.erb b/app/views/staffs/people/relationships/_table.html.erb index 026ae18..1014219 100644 --- a/app/views/staffs/people/relationships/_table.html.erb +++ b/app/views/staffs/people/relationships/_table.html.erb @@ -7,9 +7,6 @@ <%= Relationship.human_attribute_name :from_date %> - - <%= Relationship.human_attribute_name :regional_office %> - @@ -19,10 +16,6 @@ <%= relationship.id %> <%= relationship_from_date_or_none relationship %> - - <%= staff_regional_office_link_or_none \ - relationship.regional_office %> - <% end %> diff --git a/app/views/staffs/people/show.html.erb b/app/views/staffs/people/show.html.erb index 46a41ab..d1c092d 100644 --- a/app/views/staffs/people/show.html.erb +++ b/app/views/staffs/people/show.html.erb @@ -62,12 +62,6 @@
<%= relationship_from_date_or_none @person.current_relationship %>
- -
<%= Relationship.human_attribute_name :regional_office %>
-
- <%= staff_regional_office_link_or_none \ - @person.current_relationship&.regional_office %> -
diff --git a/config/locales/activerecord/en.yml b/config/locales/activerecord/en.yml index a7b667c..1f0c09b 100644 --- a/config/locales/activerecord/en.yml +++ b/config/locales/activerecord/en.yml @@ -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 diff --git a/config/locales/activerecord/ru.yml b/config/locales/activerecord/ru.yml index dc22da2..d9776b0 100644 --- a/config/locales/activerecord/ru.yml +++ b/config/locales/activerecord/ru.yml @@ -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 diff --git a/db/migrate/20190930210852_remove_regional_offices.rb b/db/migrate/20190930210852_remove_regional_offices.rb new file mode 100644 index 0000000..25db9f5 --- /dev/null +++ b/db/migrate/20190930210852_remove_regional_offices.rb @@ -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 diff --git a/db/structure.sql b/db/structure.sql index 440088d..77a0834 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -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'); diff --git a/factories/people.rb b/factories/people.rb index cf6b389..2e2b895 100644 --- a/factories/people.rb +++ b/factories/people.rb @@ -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 diff --git a/factories/regional_offices.rb b/factories/regional_offices.rb deleted file mode 100644 index 4f32ab8..0000000 --- a/factories/regional_offices.rb +++ /dev/null @@ -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 diff --git a/factories/relationships.rb b/factories/relationships.rb index 1038455..c96004c 100644 --- a/factories/relationships.rb +++ b/factories/relationships.rb @@ -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) diff --git a/features/step_definitions/account.rb b/features/step_definitions/account.rb index a08c316..fc6efc4 100644 --- a/features/step_definitions/account.rb +++ b/features/step_definitions/account.rb @@ -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], diff --git a/spec/helpers/regional_offices_helper_spec.rb b/spec/helpers/regional_offices_helper_spec.rb deleted file mode 100644 index c282ecc..0000000 --- a/spec/helpers/regional_offices_helper_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe RegionalOfficesHelper do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/federal_subject_spec.rb b/spec/models/federal_subject_spec.rb index f114dcc..9d5d0b3 100644 --- a/spec/models/federal_subject_spec.rb +++ b/spec/models/federal_subject_spec.rb @@ -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 diff --git a/spec/models/regional_office_spec.rb b/spec/models/regional_office_spec.rb deleted file mode 100644 index 0afe191..0000000 --- a/spec/models/regional_office_spec.rb +++ /dev/null @@ -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 diff --git a/spec/models/relationship_spec.rb b/spec/models/relationship_spec.rb index 1b5ef10..6579c30 100644 --- a/spec/models/relationship_spec.rb +++ b/spec/models/relationship_spec.rb @@ -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 }