diff --git a/lib/geocoder/results/google.rb b/lib/geocoder/results/google.rb index de99a002ab1ee6d07d15e24910d89f37731ee0f8..cb45785fd45ee24e75fd0006d0bb3ec6831cdfe2 100644 --- a/lib/geocoder/results/google.rb +++ b/lib/geocoder/results/google.rb @@ -20,6 +20,7 @@ module Geocoder::Result return entity['long_name'] end end + return nil # no appropriate components found end def state diff --git a/test/fixtures/google_no_city_data.json b/test/fixtures/google_no_city_data.json new file mode 100644 index 0000000000000000000000000000000000000000..72c528084bec712b1ba7213ddafafbf472bdd6ae --- /dev/null +++ b/test/fixtures/google_no_city_data.json @@ -0,0 +1,44 @@ +{ + "status": "OK", + "results": [ { + "types": [ "postal_code" ], + "formatted_address": "55100, Turkey", + "address_components": [{ + "long_name": "55100", + "short_name": "55100", + "types": ["postal_code"] + }, + { + "long_name": "Turkey", + "short_name": "TR", + "types": ["country", "political"] + }], + "geometry": { + "location": { + "lat": 41.3112221, + "lng": 36.3322118 + }, + "location_type": "APPROXIMATE", + "viewport": { + "southwest": { + "lat": 41.2933411, + "lng": 36.3066331 + }, + "northeast": { + "lat": 41.3291031, + "lng": 36.3577906 + } + }, + "bounds": { + "southwest": { + "lat": 41.2933411, + "lng": 36.3066331 + }, + "northeast": { + "lat": 41.3291031, + "lng": 36.3577906 + } + } + } + } ] +} \ No newline at end of file diff --git a/test/geocoder_test.rb b/test/geocoder_test.rb index 67bc298ed36379bbc7180351432b1b2fc1a5d0d4..dacfd8e3cd88ee42e662fdde998e9f9e14f042ea 100644 --- a/test/geocoder_test.rb +++ b/test/geocoder_test.rb @@ -370,6 +370,10 @@ class GeocoderTest < Test::Unit::TestCase assert_equal "Haram", result.city end + def test_google_city_results_returns_nil_if_no_matching_component_types + result = Geocoder.search("no city data").first + assert_equal nil, result.city + end # --- Yahoo --- diff --git a/test/test_helper.rb b/test/test_helper.rb index bddff7d176abbf73598a09ad78543c5605415a6a..7364498a1cd6789706bc7500c58d0310c8c8733c 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -63,9 +63,10 @@ module Geocoder def fetch_raw_data(query, reverse = false) raise TimeoutError if query == "timeout" file = case query - when "no results"; :no_results - when "no locality"; :no_locality - else :madison_square_garden + when "no results"; :no_results + when "no locality"; :no_locality + when "no city data"; :no_city_data + else :madison_square_garden end read_fixture "google_#{file}.json" end