diff --git a/lib/geocoder/results/smarty_streets.rb b/lib/geocoder/results/smarty_streets.rb index 6bdb51437652079ad4abfe1671d4117bdc3823ac..b4850677f31e7885d266ce1c6042d87ba1d0f446 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 0000000000000000000000000000000000000000..e2da38b8dece707784b61034541443d719ded59a --- /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 710efc4613812fa08d5d0e3e099c3dc8c4ea2487..fe89335e810a836162ce73b20fc3da7a276f45f2 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