From 571ca745f2971748d8262481c2dc6fc1ca3aff11 Mon Sep 17 00:00:00 2001 From: Leonid Brujev Date: Tue, 26 Sep 2023 17:06:48 +0100 Subject: [PATCH] RUBY-2445: Adding factory for authority --- app/models/pafs_core/area.rb | 4 ++-- lib/pafs_core/data_migration/update_authorities.rb | 6 +++--- spec/factories/areas.rb | 8 +++++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/models/pafs_core/area.rb b/app/models/pafs_core/area.rb index 34466851c..2fe5df7a9 100644 --- a/app/models/pafs_core/area.rb +++ b/app/models/pafs_core/area.rb @@ -7,7 +7,7 @@ class Area < ApplicationRecord EA_AREA = "EA Area", PSO_AREA = "PSO Area", RMA_AREA = "RMA", - AUTHORITY_AREA = "Authority" + AUTHORITY = "Authority" ].freeze validates :name, :area_type, presence: true @@ -40,7 +40,7 @@ def self.rma_areas where(area_type: AREA_TYPES[3]) end - def self.authority_areas + def self.authorities where(area_type: AREA_TYPES[4]) end diff --git a/lib/pafs_core/data_migration/update_authorities.rb b/lib/pafs_core/data_migration/update_authorities.rb index c3c0bb746..693f5ff57 100644 --- a/lib/pafs_core/data_migration/update_authorities.rb +++ b/lib/pafs_core/data_migration/update_authorities.rb @@ -16,19 +16,19 @@ def up } authorities.each do |identifier, name| - authority = PafsCore::Area.find_by(area_type: PafsCore::Area::AUTHORITY_AREA, identifier: identifier) + authority = PafsCore::Area.find_by(area_type: PafsCore::Area::AUTHORITY, identifier: identifier) next if authority.present? PafsCore::Area.create( name: name, - area_type: PafsCore::Area::AUTHORITY_AREA, + area_type: PafsCore::Area::AUTHORITY, identifier: identifier ) end end def down - PafsCore::Area.where(area_type: PafsCore::Area::AUTHORITY_AREA).destroy_all + PafsCore::Area.where(area_type: PafsCore::Area::AUTHORITY).destroy_all end end end diff --git a/spec/factories/areas.rb b/spec/factories/areas.rb index f63c857db..7712612a7 100644 --- a/spec/factories/areas.rb +++ b/spec/factories/areas.rb @@ -93,7 +93,7 @@ factory :rma_area do area_type { "RMA" } - sub_type { "Local Authority" } + sub_type { PafsCore::Area.authorities.first&.identifier || create(:authority).identifier } parent { PafsCore::Area.country || create(:country) } @@ -129,5 +129,11 @@ end end end + + factory :authority do + area_type { "Authority" } + name { "Local Authority" } + identifier { "LA" } + end end end