From 31571cd88b26dcdaed64d1e593cd41ef3c98fc30 Mon Sep 17 00:00:00 2001
From: Roy Lee <royglee@gmail.com>
Date: Sat, 25 Feb 2017 12:52:29 -0800
Subject: [PATCH] Update smarty streets results coordinates method to return
 nil when both latitude and longitude do not exist

---
 lib/geocoder/results/smarty_streets.rb   | 8 +++++++-
 test/fixtures/smarty_streets_96628       | 1 +
 test/unit/lookups/smarty_streets_test.rb | 5 +++++
 3 files changed, 13 insertions(+), 1 deletion(-)
 create mode 100644 test/fixtures/smarty_streets_96628

diff --git a/lib/geocoder/results/smarty_streets.rb b/lib/geocoder/results/smarty_streets.rb
index 6bdb5143..b4850677 100644
--- a/lib/geocoder/results/smarty_streets.rb
+++ b/lib/geocoder/results/smarty_streets.rb
@@ -3,9 +3,15 @@ require 'geocoder/lookups/base'
 module Geocoder::Result
   class SmartyStreets < Base
     def coordinates
-      %w(latitude longitude).map do |i|
+      result = %w(latitude longitude).map do |i|
         zipcode_endpoint? ? zipcodes.first[i] : metadata[i]
       end
+
+      if result.compact.empty?
+        nil
+      else
+        result
+      end
     end
 
     def address
diff --git a/test/fixtures/smarty_streets_96628 b/test/fixtures/smarty_streets_96628
new file mode 100644
index 00000000..e2da38b8
--- /dev/null
+++ b/test/fixtures/smarty_streets_96628
@@ -0,0 +1 @@
+[{"input_index":0,"city_states":[{"city":"FPO","state_abbreviation":"AP","state":"ArmedForcesPacific","mailable_city":true}],"zipcodes":[{"zipcode":"96628","zipcode_type":"M","default_city":"Fpo","county_fips":"00000","county_name":"None","state_abbreviation":"AP","state":"ArmedForcesPacific","precision":"None"}]}]
diff --git a/test/unit/lookups/smarty_streets_test.rb b/test/unit/lookups/smarty_streets_test.rb
index 710efc46..fe89335e 100644
--- a/test/unit/lookups/smarty_streets_test.rb
+++ b/test/unit/lookups/smarty_streets_test.rb
@@ -47,6 +47,11 @@ class SmartyStreetsTest < GeocoderTestCase
     assert result.zipcode_endpoint?
   end
 
+  def test_smarty_streets_when_longitude_latitude_does_not_exist
+    result = Geocoder.search("96628").first
+    assert_equal nil, result.coordinates
+  end
+
   def test_no_results
     results = Geocoder.search("no results")
     assert_equal 0, results.length
-- 
GitLab