Skip to content

Commit

Permalink
Merge pull request #706 from DEFRA/feature/RUBY-2448-pafs-bau-back-of…
Browse files Browse the repository at this point in the history
…fice-add-rma

RUBY-2448: Add RMA page
  • Loading branch information
brujeo authored Sep 27, 2023
2 parents 0122d5a + 9ddd6a2 commit c5d507b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/models/pafs_core/area.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ class Area < ApplicationRecord
AUTHORITY = "Authority"
].freeze

attr_accessor :skip_identifier_validation

validates :name, :area_type, presence: true
validates :name, uniqueness: true
validates :identifier, presence: true, if: :rma? || :authority?, unless: :skip_identifier_validation
validates :identifier, uniqueness: true, if: :rma? || :authority?, unless: :skip_identifier_validation
validate :parentage
validates :area_type, inclusion: { in: AREA_TYPES }
validates :sub_type, presence: true, if: :rma?
Expand Down
1 change: 1 addition & 0 deletions app/services/pafs_core/area_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def create_child_records(areas_grouped_by_parent)
if parent || child["type"] == PafsCore::Area::AREA_TYPES[0]
begin
a = Area.new(area)
a.skip_identifier_validation = true
a.save!
rescue StandardError => e
report_error(e.message, child)
Expand Down
1 change: 1 addition & 0 deletions spec/factories/areas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@

factory :rma_area do
area_type { "RMA" }
identifier { Faker::Lorem.characters(number: 10) }
sub_type { PafsCore::Area.authorities.first&.identifier || create(:authority).identifier }

parent { PafsCore::Area.country || create(:country) }
Expand Down

0 comments on commit c5d507b

Please sign in to comment.