From 8fc07d50b38d7546b074f529fad7d9342ad3358f Mon Sep 17 00:00:00 2001 From: "Eric L. Truitte, MBA" Date: Tue, 3 Sep 2019 10:22:19 -0400 Subject: [PATCH] Allow unaltered shelters to be updated during import --- app/importers/fema_importer.rb | 2 +- app/jobs/import_fema_shelters_job.rb | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/importers/fema_importer.rb b/app/importers/fema_importer.rb index 0b95b11..8bd166d 100644 --- a/app/importers/fema_importer.rb +++ b/app/importers/fema_importer.rb @@ -44,7 +44,7 @@ def self.shelters # If not closed, the sheter will likely have staff available to answer Questions # if shelter-seekers do show up even if they are not accepting at this time. - active: status != 'CLOSED', + archived: !(status != 'CLOSED'), # Yes, double negative accepting: accepting } diff --git a/app/jobs/import_fema_shelters_job.rb b/app/jobs/import_fema_shelters_job.rb index 7c90b41..29ef99a 100644 --- a/app/jobs/import_fema_shelters_job.rb +++ b/app/jobs/import_fema_shelters_job.rb @@ -36,7 +36,7 @@ def deduplicated_import!(data) Shelter.create!(data) 1 else - unarchive!(shelter) + update!(shelter, data) 0 end end @@ -66,10 +66,13 @@ def find_by_source(data) Shelter.unscope(:where).where('LOWER(TRIM(source)) = ?', data[:source].strip.downcase) end - def unarchive!(shelter) + def update!(shelter, data) + _data = shelter.updated_by.blank? ? data : {} if shelter.archived logger.info "Unarchiving pre-existing shelter with ID #{shelter.id}" - shelter.update_columns(archived: false, updated_at: Time.now) + _data[:archived] = false end + shelter.assign_attributes(_data) + shelter.save if shelter.changed? end end