3 require File.dirname(__FILE__) + '/../test_helper'
4 require 'geocoder_controller'
6 class GeocoderControllerTest < ActionController::TestCase
8 # test all routes which lead to this controller
11 { :path => "/geocoder/search", :method => :post },
12 { :controller => "geocoder", :action => "search" }
15 { :path => "/geocoder/search_us_postcode", :method => :get },
16 { :controller => "geocoder", :action => "search_us_postcode" }
19 { :path => "/geocoder/search_uk_postcode", :method => :get },
20 { :controller => "geocoder", :action => "search_uk_postcode" }
23 { :path => "/geocoder/search_ca_postcode", :method => :get },
24 { :controller => "geocoder", :action => "search_ca_postcode" }
27 { :path => "/geocoder/search_osm_nominatim", :method => :get },
28 { :controller => "geocoder", :action => "search_osm_nominatim" }
31 { :path => "/geocoder/search_geonames", :method => :get },
32 { :controller => "geocoder", :action => "search_geonames" }
35 { :path => "/geocoder/search_osm_nominatim_reverse", :method => :get },
36 { :controller => "geocoder", :action => "search_osm_nominatim_reverse" }
39 { :path => "/geocoder/search_geonames_reverse", :method => :get },
40 { :controller => "geocoder", :action => "search_geonames_reverse" }
45 # Test identification of basic lat/lon pairs
46 def test_identify_latlon_basic
50 '+50.06773 +14.37742',
51 '+50.06773, +14.37742'
53 post :search, :query => code
54 assert_response :success
55 assert_equal ['osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
56 assert_nil @controller.params[:query]
57 assert_in_delta 50.06773, @controller.params[:lat]
58 assert_in_delta 14.37742, @controller.params[:lon]
63 # Test identification of lat/lon pairs using N/E with degrees
64 def test_identify_latlon_ne_d
66 'N50.06773 E14.37742',
67 'N50.06773, E14.37742',
68 '50.06773N 14.37742E',
69 '50.06773N, 14.37742E'
71 post :search, :query => code
72 assert_response :success
73 assert_equal ['osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
74 assert_nil @controller.params[:query]
75 assert_in_delta 50.06773, @controller.params[:lat]
76 assert_in_delta 14.37742, @controller.params[:lon]
81 # Test identification of lat/lon pairs using N/W with degrees
82 def test_identify_latlon_nw_d
84 'N50.06773 W14.37742',
85 'N50.06773, W14.37742',
86 '50.06773N 14.37742W',
87 '50.06773N, 14.37742W'
89 post :search, :query => code
90 assert_response :success
91 assert_equal ['osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
92 assert_nil @controller.params[:query]
93 assert_in_delta 50.06773, @controller.params[:lat]
94 assert_in_delta -14.37742, @controller.params[:lon]
99 # Test identification of lat/lon pairs using S/E with degrees
100 def test_identify_latlon_se_d
102 'S50.06773 E14.37742',
103 'S50.06773, E14.37742',
104 '50.06773S 14.37742E',
105 '50.06773S, 14.37742E'
107 post :search, :query => code
108 assert_response :success
109 assert_equal ['osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
110 assert_nil @controller.params[:query]
111 assert_in_delta -50.06773, @controller.params[:lat]
112 assert_in_delta 14.37742, @controller.params[:lon]
117 # Test identification of lat/lon pairs using S/W with degrees
118 def test_identify_latlon_sw_d
120 'S50.06773 W14.37742',
121 'S50.06773, W14.37742',
122 '50.06773S 14.37742W',
123 '50.06773S, 14.37742W'
125 post :search, :query => code
126 assert_response :success
127 assert_equal ['osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
128 assert_nil @controller.params[:query]
129 assert_in_delta -50.06773, @controller.params[:lat]
130 assert_in_delta -14.37742, @controller.params[:lon]
135 # Test identification of lat/lon pairs using N/E with degrees/mins
136 def test_identify_latlon_ne_dm
138 'N 50° 04.064 E 014° 22.645',
139 "N 50° 04.064' E 014° 22.645",
140 "N 50° 04.064', E 014° 22.645'",
141 'N50° 04.064 E14° 22.645',
142 'N 50 04.064 E 014 22.645',
143 'N50 4.064 E14 22.645',
144 "50° 04.064' N, 014° 22.645' E"
146 post :search, :query => code
147 assert_response :success
148 assert_equal ['osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
149 assert_nil @controller.params[:query]
150 assert_in_delta 50.06773, @controller.params[:lat]
151 assert_in_delta 14.37742, @controller.params[:lon]
156 # Test identification of lat/lon pairs using N/W with degrees/mins
157 def test_identify_latlon_nw_dm
159 'N 50° 04.064 W 014° 22.645',
160 "N 50° 04.064' W 014° 22.645",
161 "N 50° 04.064', W 014° 22.645'",
162 'N50° 04.064 W14° 22.645',
163 'N 50 04.064 W 014 22.645',
164 'N50 4.064 W14 22.645',
165 "50° 04.064' N, 014° 22.645' W"
167 post :search, :query => code
168 assert_response :success
169 assert_equal ['osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
170 assert_nil @controller.params[:query]
171 assert_in_delta 50.06773, @controller.params[:lat]
172 assert_in_delta -14.37742, @controller.params[:lon]
177 # Test identification of lat/lon pairs using S/E with degrees/mins
178 def test_identify_latlon_se_dm
180 'S 50° 04.064 E 014° 22.645',
181 "S 50° 04.064' E 014° 22.645",
182 "S 50° 04.064', E 014° 22.645'",
183 'S50° 04.064 E14° 22.645',
184 'S 50 04.064 E 014 22.645',
185 'S50 4.064 E14 22.645',
186 "50° 04.064' S, 014° 22.645' E"
188 post :search, :query => code
189 assert_response :success
190 assert_equal ['osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
191 assert_nil @controller.params[:query]
192 assert_in_delta -50.06773, @controller.params[:lat]
193 assert_in_delta 14.37742, @controller.params[:lon]
198 # Test identification of lat/lon pairs using S/W with degrees/mins
199 def test_identify_latlon_sw_dm
201 'S 50° 04.064 W 014° 22.645',
202 "S 50° 04.064' W 014° 22.645",
203 "S 50° 04.064', W 014° 22.645'",
204 'S50° 04.064 W14° 22.645',
205 'S 50 04.064 W 014 22.645',
206 'S50 4.064 W14 22.645',
207 "50° 04.064' S, 014° 22.645' W"
209 post :search, :query => code
210 assert_response :success
211 assert_equal ['osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
212 assert_nil @controller.params[:query]
213 assert_in_delta -50.06773, @controller.params[:lat]
214 assert_in_delta -14.37742, @controller.params[:lon]
219 # Test identification of lat/lon pairs using N/E with degrees/mins/secs
220 def test_identify_latlon_ne_dms
222 "N 50° 4' 03.828\" E 14° 22' 38.712\"",
223 "N 50° 4' 03.828\", E 14° 22' 38.712\"",
224 "N 50° 4′ 03.828″, E 14° 22′ 38.712″",
225 'N50 4 03.828 E14 22 38.712',
226 'N50 4 03.828, E14 22 38.712',
227 "50°4'3.828\"N 14°22'38.712\"E"
229 post :search, :query => code
230 assert_response :success
231 assert_equal ['osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
232 assert_nil @controller.params[:query]
233 assert_in_delta 50.06773, @controller.params[:lat]
234 assert_in_delta 14.37742, @controller.params[:lon]
239 # Test identification of lat/lon pairs using N/W with degrees/mins/secs
240 def test_identify_latlon_nw_dms
242 "N 50° 4' 03.828\" W 14° 22' 38.712\"",
243 "N 50° 4' 03.828\", W 14° 22' 38.712\"",
244 "N 50° 4′ 03.828″, W 14° 22′ 38.712″",
245 'N50 4 03.828 W14 22 38.712',
246 'N50 4 03.828, W14 22 38.712',
247 "50°4'3.828\"N 14°22'38.712\"W"
249 post :search, :query => code
250 assert_response :success
251 assert_equal ['osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
252 assert_nil @controller.params[:query]
253 assert_in_delta 50.06773, @controller.params[:lat]
254 assert_in_delta -14.37742, @controller.params[:lon]
259 # Test identification of lat/lon pairs using S/E with degrees/mins/secs
260 def test_identify_latlon_se_dms
262 "S 50° 4' 03.828\" E 14° 22' 38.712\"",
263 "S 50° 4' 03.828\", E 14° 22' 38.712\"",
264 "S 50° 4′ 03.828″, E 14° 22′ 38.712″",
265 'S50 4 03.828 E14 22 38.712',
266 'S50 4 03.828, E14 22 38.712',
267 "50°4'3.828\"S 14°22'38.712\"E"
269 post :search, :query => code
270 assert_response :success
271 assert_equal ['osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
272 assert_nil @controller.params[:query]
273 assert_in_delta -50.06773, @controller.params[:lat]
274 assert_in_delta 14.37742, @controller.params[:lon]
279 # Test identification of lat/lon pairs using S/W with degrees/mins/secs
280 def test_identify_latlon_sw_dms
282 "S 50° 4' 03.828\" W 14° 22' 38.712\"",
283 "S 50° 4' 03.828\", W 14° 22' 38.712\"",
284 "S 50° 4′ 03.828″, W 14° 22′ 38.712″",
285 'S50 4 03.828 W14 22 38.712',
286 'S50 4 03.828, W14 22 38.712',
287 "50°4'3.828\"S 14°22'38.712\"W"
289 post :search, :query => code
290 assert_response :success
291 assert_equal ['osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
292 assert_nil @controller.params[:query]
293 assert_in_delta -50.06773, @controller.params[:lat]
294 assert_in_delta -14.37742, @controller.params[:lon]
299 # Test identification of US zipcodes
300 def test_identify_us_postcode
305 post :search, query: code
306 assert_response :success
307 assert_equal ['us_postcode', 'osm_nominatim'], assigns(:sources)
312 # Test identification of UK postcodes using examples from
313 # http://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom
314 def test_identify_uk_postcode
323 post :search, query: code
324 assert_response :success
325 assert_equal ['uk_postcode', 'osm_nominatim'], assigns(:sources)
330 # Test identification of Canadian postcodes
331 def test_identify_ca_postcode
332 post :search, query: 'A1B 2C3'
333 assert_response :success
334 assert_equal ['ca_postcode', 'osm_nominatim'], assigns(:sources)
338 # Test identification fall through to the default case
339 def test_identify_default
340 post :search, query: 'foo bar baz'
341 assert_response :success
342 assert_equal ['osm_nominatim'], assigns(:sources)