Skip to content
Snippets Groups Projects
Commit dee81642 authored by Jeff Keen's avatar Jeff Keen Committed by Alex Reisner
Browse files

Return nil when Google provides no city.

Fixes #56
parent f2b5e62d
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,7 @@ module Geocoder::Result ...@@ -20,6 +20,7 @@ module Geocoder::Result
return entity['long_name'] return entity['long_name']
end end
end end
return nil # no appropriate components found
end end
def state def state
......
{
"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
...@@ -370,6 +370,10 @@ class GeocoderTest < Test::Unit::TestCase ...@@ -370,6 +370,10 @@ class GeocoderTest < Test::Unit::TestCase
assert_equal "Haram", result.city assert_equal "Haram", result.city
end 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 --- # --- Yahoo ---
......
...@@ -63,9 +63,10 @@ module Geocoder ...@@ -63,9 +63,10 @@ module Geocoder
def fetch_raw_data(query, reverse = false) def fetch_raw_data(query, reverse = false)
raise TimeoutError if query == "timeout" raise TimeoutError if query == "timeout"
file = case query file = case query
when "no results"; :no_results when "no results"; :no_results
when "no locality"; :no_locality when "no locality"; :no_locality
else :madison_square_garden when "no city data"; :no_city_data
else :madison_square_garden
end end
read_fixture "google_#{file}.json" read_fixture "google_#{file}.json"
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment