diff --git a/app/models/relationship.rb b/app/models/relationship.rb index 6db3621..4a9cc78 100644 --- a/app/models/relationship.rb +++ b/app/models/relationship.rb @@ -3,7 +3,12 @@ class Relationship < ApplicationRecord pg_enum :status, %i[supporter excluded member] - pg_enum :role, %i[federal_manager regional_manager regional_supervisor] + pg_enum :role, %i[ + federal_manager + federal_supervisor + regional_manager + regional_supervisor + ] ################ # Associations # @@ -19,6 +24,8 @@ class Relationship < ApplicationRecord scope :federal_managers, -> { where(role: :federal_manager) } + scope :federal_supervisors, -> { where(role: :federal_supervisor) } + ############### # Validations # ############### diff --git a/config/locales/enums/ru.yml b/config/locales/enums/ru.yml index a845acb..3d3d11b 100644 --- a/config/locales/enums/ru.yml +++ b/config/locales/enums/ru.yml @@ -9,6 +9,7 @@ ru: member: Член партии relationship_role: federal_manager: Член федерального комитета + federal_supervisor: Член центральной контрольно-ревизионной комиссии regional_manager: Член руководящего комитета регионального отделения regional_supervisor: >- Член контрольно-ревизионной комиссии регионального отделения diff --git a/db/migrate/20181129203927_initial_migration.rb b/db/migrate/20181129203927_initial_migration.rb index f6318de..145ef5e 100644 --- a/db/migrate/20181129203927_initial_migration.rb +++ b/db/migrate/20181129203927_initial_migration.rb @@ -17,6 +17,7 @@ private enum :relationship_role, %i[ federal_manager + federal_supervisor regional_manager regional_supervisor ] diff --git a/db/structure.sql b/db/structure.sql index a800f8f..4b69032 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -44,6 +44,7 @@ CREATE TYPE public.person_comment_origin AS ENUM ( CREATE TYPE public.relationship_role AS ENUM ( 'federal_manager', + 'federal_supervisor', 'regional_manager', 'regional_supervisor' ); diff --git a/factories/relationships.rb b/factories/relationships.rb index ce6684c..e6d40d5 100644 --- a/factories/relationships.rb +++ b/factories/relationships.rb @@ -29,6 +29,10 @@ FactoryBot.define do role { :federal_manager } end + factory :federal_supervisor_relationship, parent: :member_relationship do + role { :federal_supervisor } + end + factory :regional_manager_relationship, parent: :member_relationship do role { :regional_manager } end diff --git a/spec/models/relationship_spec.rb b/spec/models/relationship_spec.rb index c24a495..db13697 100644 --- a/spec/models/relationship_spec.rb +++ b/spec/models/relationship_spec.rb @@ -72,13 +72,31 @@ RSpec.describe Relationship do let!(:relationship3) { create :excluded_supporter_relationship } let!(:relationship3) { create :excluded_member_relationship } let!(:relationship4) { create :federal_manager_relationship } - let!(:relationship5) { create :regional_manager_relationship } - let!(:relationship6) { create :regional_supervisor_relationship } - let!(:relationship7) { create :federal_manager_relationship } + let!(:relationship5) { create :federal_supervisor_relationship } + let!(:relationship6) { create :regional_manager_relationship } + let!(:relationship7) { create :regional_supervisor_relationship } + let!(:relationship8) { create :federal_manager_relationship } specify do expect(described_class.federal_managers).to \ - eq [relationship4, relationship7] + eq [relationship4, relationship8] + end + end + + describe '.federal_supervisors' do + let!(:relationship1) { create :supporter_relationship } + let!(:relationship2) { create :member_relationship } + let!(:relationship3) { create :excluded_supporter_relationship } + let!(:relationship3) { create :excluded_member_relationship } + let!(:relationship4) { create :federal_manager_relationship } + let!(:relationship5) { create :federal_supervisor_relationship } + let!(:relationship6) { create :regional_manager_relationship } + let!(:relationship7) { create :regional_supervisor_relationship } + let!(:relationship8) { create :federal_supervisor_relationship } + + specify do + expect(described_class.federal_supervisors).to \ + eq [relationship5, relationship8] end end end