Skip to content
Snippets Groups Projects
Commit c439bdf4 authored by Rob Murray's avatar Rob Murray
Browse files

Handle responses that only have one component in the Location field, assume...

Handle responses that only have one component in the Location field, assume this is a county and so return blank city
parent 0d93d6c5
No related branches found
No related tags found
No related merge requests found
......@@ -21,7 +21,7 @@ module Geocoder::Result
def city
# is this too big a jump to assume that the API always
# returns a City, County as the last elements?
city = @data['Location'].split(',')[-2]
city = @data['Location'].split(',')[-2] || blank_result
city.strip
end
......
[{"Location":"Hampshire","Easting":"448701","Northing":"126642","Latitude":"51.037","Longitude":"-1.3068","OsGrid":"SU 48701 26642","Accuracy":"Standard"}]
\ No newline at end of file
......@@ -27,6 +27,15 @@ class PostcodeAnywhereUkTest < GeocoderTestCase
assert_equal 'Hallow', results.first.city
end
def test_result_components_with_county
results = Geocoder.search('hampshire')
assert_equal 1, results.size
assert_equal 'Hampshire, SU 48701 26642', results.first.address
assert_equal [51.037, -1.3068], results.first.coordinates
assert_equal '', results.first.city
end
def test_no_results
assert_equal [], Geocoder.search('no results')
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