Browse Source

Import locations that belong to now inactive schemes (#984)

We were previously blocking the import of locations that belonged to schemes where the end date was before the current date. This meant that we were unable to import logs that are associated with schemes that _were_ valid, but have since expired.
pull/985/head
James Rose 2 years ago committed by GitHub
parent
commit
978d72f7e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      app/services/imports/scheme_location_import_service.rb
  2. 15
      spec/services/imports/scheme_location_import_service_spec.rb

6
app/services/imports/scheme_location_import_service.rb

@ -97,8 +97,6 @@ module Imports
end
def add_location(scheme, attributes)
if attributes["end_date"].nil? || attributes["end_date"] >= Time.zone.now
begin
Location.create!(
name: attributes["location_name"],
postcode: attributes["postcode"],
@ -113,10 +111,6 @@ module Imports
rescue ActiveRecord::RecordNotUnique
@logger.warn("Location is already present with legacy ID #{attributes['location_old_id']}, skipping")
end
else
@logger.warn("Location with legacy ID #{attributes['location_old_id']} is expired (#{attributes['end_date']}), skipping")
end
end
def find_scheme_to_merge(attributes)
Scheme.find_by(

15
spec/services/imports/scheme_location_import_service_spec.rb

@ -160,21 +160,6 @@ RSpec.describe Imports::SchemeLocationImportService do
expect(location.scheme.confirmed).to be_truthy
end
context "and the end date is before the current date" do
before do
Timecop.freeze(2022, 6, 1)
location_xml.at_xpath("//scheme:end-date").content = "2022-05-01"
end
after { Timecop.unfreeze }
it "does not create the location" do
expect(logger).to receive(:warn).with("Location with legacy ID 0ae7ad6dc0f1cf7ef33c18cc8c108bebc1b4923e is expired (2022-05-01 00:00:00 +0100), skipping")
expect { location_service.create_scheme_location(location_xml) }
.not_to change(Location, :count)
end
end
context "and we import the same location twice" do
before { location_service.create_scheme_location(location_xml) }

Loading…
Cancel
Save