-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtest_geo_location.rb
147 lines (107 loc) · 3.52 KB
/
test_geo_location.rb
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
require 'helper'
class TestGeoLocation < Test::Unit::TestCase
context "on Max Mind" do
setup do
GeoLocation::use = :maxmind
GeoLocation::dev = 'US,NY,Jamaica,40.676300,-73.775200'
GeoLocation::dev_ip = '24.24.24.24'
@location = GeoLocation.find()
end
should "use Max Mind" do
assert_equal :maxmind, GeoLocation::use
end
should "find ip 24.24.24.24" do
assert_equal '24.24.24.24', @location[:ip]
end
should "find US country_code" do
assert_equal 'US', @location[:country_code]
end
should "find United States country" do
assert_equal 'United States', @location[:country]
end
should "find NY region" do
assert_equal 'NY', @location[:region]
end
should "find Jamaica city" do
assert_equal 'Jamaica', @location[:city]
end
should "find latitude 40.676300" do
assert_equal '40.676300', @location[:latitude]
end
should "find longitude -73.775200" do
assert_equal '-73.775200', @location[:longitude]
end
should "find timezone America/New_York" do
assert_equal 'America/New_York', @location[:timezone]
end
end
context "on HostIP" do
setup do
GeoLocation::use = :hostip
GeoLocation::dev = 'US,NY,Liverpool,43.1059,-76.2099'
GeoLocation::dev_ip = '24.24.24.24'
@location = GeoLocation.find()
end
should "use HostIP" do
assert_equal :hostip, GeoLocation::use
end
should "find ip 24.24.24.24" do
assert_equal '24.24.24.24', @location[:ip]
end
should "find US country_code" do
assert_equal 'US', @location[:country_code]
end
should "find US country" do
assert_equal 'United States', @location[:country]
end
should "find NY region" do
assert_equal 'NY', @location[:region]
end
should "find Liverpool city" do
assert_equal 'Liverpool', @location[:city]
end
should "find latitude 43.1059" do
assert_equal '43.1059', @location[:latitude]
end
should "find longitude -76.2099" do
assert_equal '-76.2099', @location[:longitude]
end
should "find timezone America/New_York" do
assert_equal 'America/New_York', @location[:timezone]
end
end
context 'on timezones' do
setup do
GeoLocation::use = :maxmind
GeoLocation::dev = 'US,NY,Jamaica,40.676300,-73.775200'
GeoLocation::dev_ip = '24.24.24.24'
end
should "find America/Edmonton timezone" do
assert_equal 'America/Edmonton', GeoLocation.timezone('CA', 'AB')
end
should "find Europe/London timezone" do
assert_equal 'Europe/London', GeoLocation.timezone('GB')
end
should "find Europe/London timezone" do
assert_equal 'Europe/London', GeoLocation.timezone('GB')
end
should "find Europe/London timezone" do
assert_equal 'Europe/London', GeoLocation.timezone('GB', nil)
end
should "have defined timezones" do
GeoLocation.timezone('CA', 'AB')
assert_equal false, GeoLocation::timezones.empty?
end
end
context 'on countries' do
should "find country Canada" do
assert_equal 'Canada', GeoLocation.country('CA')
end
should "find country United States" do
assert_equal 'United States', GeoLocation.country('US')
end
should "find country United Kingdom" do
assert_equal 'United Kingdom', GeoLocation.country('GB')
end
end
end