Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# encoding: utf-8
require 'test_helper'
class ServicesTest < Test::Unit::TestCase
# --- Google ---
def test_google_result_components
result = Geocoder.search("Madison Square Garden, New York, NY").first
assert_equal "Manhattan",
result.address_components_of_type(:sublocality).first['long_name']
end
def test_google_returns_city_when_no_locality_in_result
result = Geocoder.search("no locality").first
assert_equal "Haram", result.city
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 ---
def test_yahoo_result_components
Geocoder::Configuration.lookup = :yahoo
result = Geocoder.search("Madison Square Garden, New York, NY").first
assert_equal "10001", result.postal_code
end
def test_yahoo_address_formatting
Geocoder::Configuration.lookup = :yahoo
result = Geocoder.search("Madison Square Garden, New York, NY").first
assert_equal "Madison Square Garden, New York, NY 10001, United States",
result.address
end
# --- Yandex ---
def test_yandex_with_invalid_key
# keep test output clean: suppress timeout warning
orig = $VERBOSE; $VERBOSE = nil
Geocoder::Configuration.lookup = :yandex
assert_equal [], Geocoder.search("invalid key")
$VERBOSE = orig
end
# --- Geocoder.ca ---
def test_geocoder_ca_result_components
Geocoder::Configuration.lookup = :geocoder_ca
result = Geocoder.search([45.423733, -75.676333]).first
assert_equal "CA", result.country_code
assert_equal "289 Somerset ST E, Ottawa, ON K1N6W1, Canada", result.address
end
# --- FreeGeoIp ---
def test_freegeoip_result_on_ip_address_search
result = Geocoder.search("74.200.247.59").first
assert result.is_a?(Geocoder::Result::Freegeoip)
end
def test_freegeoip_result_components
result = Geocoder.search("74.200.247.59").first
assert_equal "Plano, TX 75093, United States", result.address
end
# --- Bing ---
def test_bing_result_components
Geocoder::Configuration.lookup = :bing
result = Geocoder.search("Madison Square Garden, New York, NY").first
assert_equal "Madison Square Garden, NY", result.address
assert_equal "NY", result.state
assert_equal "New York", result.city
end
def test_bing_no_results
Geocoder::Configuration.lookup = :bing
results = Geocoder.search("no results")
assert_equal 0, results.length
end
end