From 3f47eb2f96f1d389e517455c8602d951d3368c0e Mon Sep 17 00:00:00 2001 From: Sid Shanker Date: Tue, 20 Dec 2016 09:34:12 -0800 Subject: [PATCH] Allow reintroducing deleted rains. --- app/models/thing.rb | 5 ++++- test/models/thing_test.rb | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/thing.rb b/app/models/thing.rb index 125a10f0..96a87858 100644 --- a/app/models/thing.rb +++ b/app/models/thing.rb @@ -75,9 +75,12 @@ def self._drain_params(drain) def self._create_or_update_drain(drain) city_id = drain['PUC_Maximo_Asset_ID'].gsub('N-', '') - thing = Thing.where(city_id: city_id).first_or_initialize + thing = Thing.unscoped.where(city_id: city_id).first_or_initialize if thing.new_record? Rails.logger.info("Creating thing #{city_id}") + elsif + thing.restore! + Rails.logger.info("Recreating deleted thing #{city_id}") else Rails.logger.info("Updating thing #{city_id}") end diff --git a/test/models/thing_test.rb b/test/models/thing_test.rb index 7cca8c81..e4789459 100644 --- a/test/models/thing_test.rb +++ b/test/models/thing_test.rb @@ -21,9 +21,13 @@ class ThingTest < ActiveSupport::TestCase thing_1 = things(:thing_1) thing_11 = things(:thing_11) + deleted_drain = things(:thing_3) + deleted_drain.destroy! + fake_url = 'http://sf-drain-data.org' fake_response = [ 'PUC_Maximo_Asset_ID,Drain_Type,System_Use_Code,Location', + 'N-3,Catch Basin Drain,ABC,"(42.38, -71.07)"', 'N-11,Catch Basin Drain,ABC,"(37.75, -122.40)"', 'N-12,Catch Basin Drain,DEF,"(39.75, -121.40)"', ].join("\n") @@ -39,6 +43,9 @@ class ThingTest < ActiveSupport::TestCase # Asserts thing_1 is deleted assert_nil Thing.find_by(id: thing_1.id) + # Asserts thing_3 is reified + assert_equal Thing.find_by(city_id: 3).id, deleted_drain.id + # Asserts creates new drain new_drain = Thing.find_by(city_id: 12) assert_not_nil new_drain