Skip to content

Commit

Permalink
Merge pull request #704 from DEFRA/feature/ruby-2445-authority-factory
Browse files Browse the repository at this point in the history
RUBY-2445: Adding factory for authority
  • Loading branch information
brujeo authored Sep 26, 2023
2 parents f95a2ac + 571ca74 commit 0122d5a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/models/pafs_core/area.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions lib/pafs_core/data_migration/update_authorities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion spec/factories/areas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down Expand Up @@ -129,5 +129,11 @@
end
end
end

factory :authority do
area_type { "Authority" }
name { "Local Authority" }
identifier { "LA" }
end
end
end

0 comments on commit 0122d5a

Please sign in to comment.