Skip to content

Commit

Permalink
Allow reintroducing deleted rains.
Browse files Browse the repository at this point in the history
  • Loading branch information
squidarth committed Dec 20, 2016
1 parent 7aa3911 commit 3f47eb2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/models/thing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/models/thing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down

0 comments on commit 3f47eb2

Please sign in to comment.