diff --git a/app/services/imports/scheme_location_import_service.rb b/app/services/imports/scheme_location_import_service.rb index 3af2845f5..49c1e91c5 100644 --- a/app/services/imports/scheme_location_import_service.rb +++ b/app/services/imports/scheme_location_import_service.rb @@ -113,6 +113,7 @@ module Imports if attributes["end_date"] location.location_deactivation_periods.create!(deactivation_date: attributes["end_date"]) end + location rescue ActiveRecord::RecordNotUnique @logger.warn("Location is already present with legacy ID #{attributes['location_old_id']}, skipping") rescue ActiveRecord::RecordInvalid diff --git a/spec/services/imports/scheme_location_import_service_spec.rb b/spec/services/imports/scheme_location_import_service_spec.rb index e74067cae..0d7b4cbd4 100644 --- a/spec/services/imports/scheme_location_import_service_spec.rb +++ b/spec/services/imports/scheme_location_import_service_spec.rb @@ -156,10 +156,15 @@ RSpec.describe Imports::SchemeLocationImportService do expect(location.scheme.primary_client_group).to eq("Older people with support needs") expect(location.scheme.secondary_client_group).to be_nil expect(location.scheme.sensitive).to eq("No") - expect(location.scheme.end_date).to eq("2050-12-31") expect(location.scheme.confirmed).to be_truthy end + it "creates a deactivation period" do + location = location_service.create_scheme_location(location_xml) + expect(location.location_deactivation_periods.count).to eq(1) + expect(location.location_deactivation_periods.first.deactivation_date).to eq(Time.zone.local(2050, 12, 31)) + end + context "and we import the same location twice" do before { location_service.create_scheme_location(location_xml) }