diff --git a/lib/geocoder/results/postcode_anywhere_uk.rb b/lib/geocoder/results/postcode_anywhere_uk.rb index 9b402d8d62ebdef718daba66d43eea60aaddf607..abf13f7193918356dea542a611062372c1ced453 100644 --- a/lib/geocoder/results/postcode_anywhere_uk.rb +++ b/lib/geocoder/results/postcode_anywhere_uk.rb @@ -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 diff --git a/test/fixtures/postcode_anywhere_uk_geocode_v2_00_hampshire b/test/fixtures/postcode_anywhere_uk_geocode_v2_00_hampshire new file mode 100644 index 0000000000000000000000000000000000000000..6eb2a4a60abc9255f03329b9cd4cee001bba0eaf --- /dev/null +++ b/test/fixtures/postcode_anywhere_uk_geocode_v2_00_hampshire @@ -0,0 +1 @@ +[{"Location":"Hampshire","Easting":"448701","Northing":"126642","Latitude":"51.037","Longitude":"-1.3068","OsGrid":"SU 48701 26642","Accuracy":"Standard"}] \ No newline at end of file diff --git a/test/unit/lookups/postcode_anywhere_uk_test.rb b/test/unit/lookups/postcode_anywhere_uk_test.rb index b49c5cd3bb5c08f741b58f8badb671b36fb80f3c..83f526ec212e3b171911f69df19104d2491ce0f0 100644 --- a/test/unit/lookups/postcode_anywhere_uk_test.rb +++ b/test/unit/lookups/postcode_anywhere_uk_test.rb @@ -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