diff --git a/test/fixtures/yandex_no_city_and_town b/test/fixtures/yandex_no_city_and_town new file mode 100644 index 0000000000000000000000000000000000000000..4493bf3fcd7e1cacada00c4eb7f03cd62ec29bc3 --- /dev/null +++ b/test/fixtures/yandex_no_city_and_town @@ -0,0 +1,112 @@ +{ + "response":{ + "GeoObjectCollection":{ + "metaDataProperty":{ + "GeocoderResponseMetaData":{ + "request":"57.423359,55.892596", + "found":"3", + "results":"10", + "Point":{ + "pos":"57.423359 55.892596" + } + } + }, + "featureMember":[ + { + "GeoObject":{ + "metaDataProperty":{ + "GeocoderMetaData":{ + "kind":"area", + "text":"РоÑÑиÑ, реÑпублика БашкортоÑтан, КараидельÑкий район", + "precision":"other", + "AddressDetails":{ + "Country":{ + "AddressLine":"реÑпублика БашкортоÑтан, КараидельÑкий район", + "CountryNameCode":"RU", + "CountryName":"РоÑÑиÑ", + "AdministrativeArea":{ + "AdministrativeAreaName":"реÑпублика БашкортоÑтан", + "SubAdministrativeArea":{ + "SubAdministrativeAreaName":"КараидельÑкий район" + } + } + } + } + } + }, + "description":"реÑпублика БашкортоÑтан, РоÑÑиÑ", + "name":"КараидельÑкий район", + "boundedBy":{ + "Envelope":{ + "lowerCorner":"56.231384 55.462814", + "upperCorner":"57.705348 56.076117" + } + }, + "Point":{ + "pos":"57.423359 55.892596" + } + } + }, + { + "GeoObject":{ + "metaDataProperty":{ + "GeocoderMetaData":{ + "kind":"province", + "text":"РоÑÑиÑ, реÑпублика БашкортоÑтан", + "precision":"other", + "AddressDetails":{ + "Country":{ + "AddressLine":"реÑпублика БашкортоÑтан", + "CountryNameCode":"RU", + "CountryName":"РоÑÑиÑ", + "AdministrativeArea":{ + "AdministrativeAreaName":"реÑпублика БашкортоÑтан" + } + } + } + } + }, + "description":"РоÑÑиÑ", + "name":"реÑпублика БашкортоÑтан", + "boundedBy":{ + "Envelope":{ + "lowerCorner":"53.157475 51.571991", + "upperCorner":"60.001577 56.533651" + } + }, + "Point":{ + "pos":"56.579526 54.127354" + } + } + }, + { + "GeoObject":{ + "metaDataProperty":{ + "GeocoderMetaData":{ + "kind":"country", + "text":"РоÑÑиÑ", + "precision":"other", + "AddressDetails":{ + "Country":{ + "CountryNameCode":"RU", + "CountryName":"РоÑÑиÑ" + } + } + } + }, + "name":"РоÑÑиÑ", + "boundedBy":{ + "Envelope":{ + "lowerCorner":"19.641673 36.84312", + "upperCorner":"179.999997 81.848739" + } + }, + "Point":{ + "pos":"37.617761 55.755773" + } + } + } + ] + } + } +} \ No newline at end of file diff --git a/test/result_test.rb b/test/result_test.rb index 6fa142073fbf2f15dfb09beda9c774c6b3b973e7..819976ce364e7b2684cef92a3e6ef0c98b10a421 100644 --- a/test/result_test.rb +++ b/test/result_test.rb @@ -4,18 +4,36 @@ require 'test_helper' class ResultTest < Test::Unit::TestCase def test_result_has_required_attributes - all_lookups.each do |l| - Geocoder::Configuration.lookup = l + Geocoder::Lookup.all_services_except_test.each do |l| + Geocoder.configure(:lookup => l) + set_api_key!(l) result = Geocoder.search([45.423733, -75.676333]).first assert_result_has_required_attributes(result) end end + # Redefine Yandex to work with fixture without city and town + class Yandex + private + def default_fixture_filename + "yandex_no_city_and_town" + end + end + + + def test_yandex_result_without_city_has_not_raises_exception + Geocoder.configure(:lookup => :yandex) + set_api_key!(:yandex) + result = Geocoder.search([45.423733, -75.676333]).first + assert result.city, "" + end + + private # ------------------------------------------------------------------ def assert_result_has_required_attributes(result) - m = "Lookup #{Geocoder::Configuration.lookup} does not support %s attribute." + m = "Lookup #{Geocoder.config.lookup} does not support %s attribute." assert result.coordinates.is_a?(Array), m % "coordinates" assert result.latitude.is_a?(Float), m % "latitude" assert result.longitude.is_a?(Float), m % "longitude"