diff --git a/lib/geocoder/results/yandex.rb b/lib/geocoder/results/yandex.rb index f14f8bfd72f7b23827f8cc9211df4eb6f78eb16b..eb42548c5547201d223bf6ffa4b539b6f25ef664 100644 --- a/lib/geocoder/results/yandex.rb +++ b/lib/geocoder/results/yandex.rb @@ -25,11 +25,19 @@ module Geocoder::Result end def country - address_details['CountryName'] + if address_details + address_details['CountryName'] + else + "" + end end def country_code - address_details['CountryNameCode'] + if address_details + address_details['CountryNameCode'] + else + "" + end end def state diff --git a/test/fixtures/yandex_black_sea b/test/fixtures/yandex_black_sea new file mode 100644 index 0000000000000000000000000000000000000000..9f7c736fae850e248ad1bb98def9c7672d8d23be --- /dev/null +++ b/test/fixtures/yandex_black_sea @@ -0,0 +1,74 @@ +{ + "response": { + "GeoObjectCollection": { + "metaDataProperty": { + "GeocoderResponseMetaData": { + "request": "32,43", + "found": "2", + "results": "10", + "Point": { + "pos": "32.000000 43.000000" + } + } + }, + "featureMember": [ + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "hydro", + "text": "Black Sea", + "precision": "other", + "AddressDetails": { + "Locality": { + "Premise": { + "PremiseName": "Black Sea" + } + } + } + } + }, + "name": "Black Sea", + "boundedBy": { + "Envelope": { + "lowerCorner": "27.442409 40.908662", + "upperCorner": "41.777787 46.627275" + } + }, + "Point": { + "pos": "34.188281 43.229215" + } + } + }, + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "hydro", + "text": "Black Sea", + "precision": "other", + "AddressDetails": { + "Locality": { + "Premise": { + "PremiseName": "Black Sea" + } + } + } + } + }, + "name": "Black Sea", + "boundedBy": { + "Envelope": { + "lowerCorner": "27.628351 40.908893", + "upperCorner": "41.777796 46.627999" + } + }, + "Point": { + "pos": "33.383633 44.235582" + } + } + } + ] + } + } +} diff --git a/test/unit/lookups/yandex_test.rb b/test/unit/lookups/yandex_test.rb index fc23292771044190d699b6e20bf9e99c46ec0544..f6357ed0a84ad69ac6c46581dc5dbdf31c7ce040 100644 --- a/test/unit/lookups/yandex_test.rb +++ b/test/unit/lookups/yandex_test.rb @@ -14,4 +14,9 @@ class YandexTest < GeocoderTestCase result.viewport end + def test_yandex_empty_results + result = Geocoder.search('black sea').first + assert_equal "", result.country_code + assert_equal "", result.country + end end