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
# encoding: utf-8
require 'test_helper'
class GoogleTest < Test::Unit::TestCase
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_result_components_contains_route
result = Geocoder.search("Madison Square Garden, New York, NY").first
assert_equal "Penn Plaza",
result.address_components_of_type(:route).first['long_name']
end
def test_google_result_components_contains_street_number
result = Geocoder.search("Madison Square Garden, New York, NY").first
assert_equal "4",
result.address_components_of_type(:street_number).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
def test_google_street_address_returns_formatted_street_address
result = Geocoder.search("Madison Square Garden, New York, NY").first
assert_equal "4 Penn Plaza", result.street_address
end
def test_google_precision
result = Geocoder.search("Madison Square Garden, New York, NY").first
assert_equal "ROOFTOP",
result.precision
end
def test_google_query_url_contains_bounds
lookup = Geocoder::Lookup::Google.new
url = lookup.query_url(Geocoder::Query.new(
"Some Intersection",
:bounds => [[40.0, -120.0], [39.0, -121.0]]
))
assert_match /bounds=40.0+%2C-120.0+%7C39.0+%2C-121.0+/, url
end
def test_google_query_url_contains_region
lookup = Geocoder::Lookup::Google.new
url = lookup.query_url(Geocoder::Query.new(
"Some Intersection",
:region => "gb"
))
assert_match /region=gb/, url
end
def test_google_query_url_contains_components_when_given_as_string
lookup = Geocoder::Lookup::Google.new
url = lookup.query_url(Geocoder::Query.new(
"Some Intersection",
:components => "locality:ES"
))
formatted = "components=" + CGI.escape("locality:ES")
assert url.include?(formatted), "Expected #{formatted} to be included in #{url}"
end
def test_google_query_url_contains_components_when_given_as_array
lookup = Geocoder::Lookup::Google.new
url = lookup.query_url(Geocoder::Query.new(
"Some Intersection",
:components => ["country:ES", "locality:ES"]
))
formatted = "components=" + CGI.escape("country:ES|locality:ES")
assert url.include?(formatted), "Expected #{formatted} to be included in #{url}"
end
end