diff --git a/app/models/pafs_core/area.rb b/app/models/pafs_core/area.rb index 2fe5df7a..055e4fe8 100644 --- a/app/models/pafs_core/area.rb +++ b/app/models/pafs_core/area.rb @@ -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? diff --git a/app/services/pafs_core/area_importer.rb b/app/services/pafs_core/area_importer.rb index b8138579..ce2e8adf 100644 --- a/app/services/pafs_core/area_importer.rb +++ b/app/services/pafs_core/area_importer.rb @@ -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) diff --git a/spec/factories/areas.rb b/spec/factories/areas.rb index 7712612a..15239d48 100644 --- a/spec/factories/areas.rb +++ b/spec/factories/areas.rb @@ -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) }