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_latlon", :method => :get },
16 { :controller => "geocoder", :action => "search_latlon" }
19 { :path => "/geocoder/search_us_postcode", :method => :get },
20 { :controller => "geocoder", :action => "search_us_postcode" }
23 { :path => "/geocoder/search_uk_postcode", :method => :get },
24 { :controller => "geocoder", :action => "search_uk_postcode" }
27 { :path => "/geocoder/search_ca_postcode", :method => :get },
28 { :controller => "geocoder", :action => "search_ca_postcode" }
31 { :path => "/geocoder/search_osm_nominatim", :method => :get },
32 { :controller => "geocoder", :action => "search_osm_nominatim" }
35 { :path => "/geocoder/search_geonames", :method => :get },
36 { :controller => "geocoder", :action => "search_geonames" }
39 { :path => "/geocoder/search_osm_nominatim_reverse", :method => :get },
40 { :controller => "geocoder", :action => "search_osm_nominatim_reverse" }
43 { :path => "/geocoder/search_geonames_reverse", :method => :get },
44 { :controller => "geocoder", :action => "search_geonames_reverse" }
49 # Test identification of basic lat/lon pairs
50 def test_identify_latlon_basic
54 '+50.06773 +14.37742',
55 '+50.06773, +14.37742'
57 post :search, :query => code
58 assert_response :success
59 assert_equal ['latlon' ,'osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
60 assert_nil @controller.params[:query]
61 assert_in_delta 50.06773, @controller.params[:lat]
62 assert_in_delta 14.37742, @controller.params[:lon]
67 # Test identification of lat/lon pairs using N/E with degrees
68 def test_identify_latlon_ne_d
70 'N50.06773 E14.37742',
71 'N50.06773, E14.37742',
72 '50.06773N 14.37742E',
73 '50.06773N, 14.37742E'
75 post :search, :query => code
76 assert_response :success
77 assert_equal ['latlon' ,'osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
78 assert_nil @controller.params[:query]
79 assert_in_delta 50.06773, @controller.params[:lat]
80 assert_in_delta 14.37742, @controller.params[:lon]
85 # Test identification of lat/lon pairs using N/W with degrees
86 def test_identify_latlon_nw_d
88 'N50.06773 W14.37742',
89 'N50.06773, W14.37742',
90 '50.06773N 14.37742W',
91 '50.06773N, 14.37742W'
93 post :search, :query => code
94 assert_response :success
95 assert_equal ['latlon' ,'osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
96 assert_nil @controller.params[:query]
97 assert_in_delta 50.06773, @controller.params[:lat]
98 assert_in_delta -14.37742, @controller.params[:lon]
103 # Test identification of lat/lon pairs using S/E with degrees
104 def test_identify_latlon_se_d
106 'S50.06773 E14.37742',
107 'S50.06773, E14.37742',
108 '50.06773S 14.37742E',
109 '50.06773S, 14.37742E'
111 post :search, :query => code
112 assert_response :success
113 assert_equal ['latlon' ,'osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
114 assert_nil @controller.params[:query]
115 assert_in_delta -50.06773, @controller.params[:lat]
116 assert_in_delta 14.37742, @controller.params[:lon]
121 # Test identification of lat/lon pairs using S/W with degrees
122 def test_identify_latlon_sw_d
124 'S50.06773 W14.37742',
125 'S50.06773, W14.37742',
126 '50.06773S 14.37742W',
127 '50.06773S, 14.37742W'
129 post :search, :query => code
130 assert_response :success
131 assert_equal ['latlon' ,'osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
132 assert_nil @controller.params[:query]
133 assert_in_delta -50.06773, @controller.params[:lat]
134 assert_in_delta -14.37742, @controller.params[:lon]
139 # Test identification of lat/lon pairs using N/E with degrees/mins
140 def test_identify_latlon_ne_dm
142 'N 50° 04.064 E 014° 22.645',
143 "N 50° 04.064' E 014° 22.645",
144 "N 50° 04.064', E 014° 22.645'",
145 'N50° 04.064 E14° 22.645',
146 'N 50 04.064 E 014 22.645',
147 'N50 4.064 E14 22.645',
148 "50° 04.064' N, 014° 22.645' E"
150 post :search, :query => code
151 assert_response :success
152 assert_equal ['latlon' ,'osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
153 assert_nil @controller.params[:query]
154 assert_in_delta 50.06773, @controller.params[:lat]
155 assert_in_delta 14.37742, @controller.params[:lon]
160 # Test identification of lat/lon pairs using N/W with degrees/mins
161 def test_identify_latlon_nw_dm
163 'N 50° 04.064 W 014° 22.645',
164 "N 50° 04.064' W 014° 22.645",
165 "N 50° 04.064', W 014° 22.645'",
166 'N50° 04.064 W14° 22.645',
167 'N 50 04.064 W 014 22.645',
168 'N50 4.064 W14 22.645',
169 "50° 04.064' N, 014° 22.645' W"
171 post :search, :query => code
172 assert_response :success
173 assert_equal ['latlon' ,'osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
174 assert_nil @controller.params[:query]
175 assert_in_delta 50.06773, @controller.params[:lat]
176 assert_in_delta -14.37742, @controller.params[:lon]
181 # Test identification of lat/lon pairs using S/E with degrees/mins
182 def test_identify_latlon_se_dm
184 'S 50° 04.064 E 014° 22.645',
185 "S 50° 04.064' E 014° 22.645",
186 "S 50° 04.064', E 014° 22.645'",
187 'S50° 04.064 E14° 22.645',
188 'S 50 04.064 E 014 22.645',
189 'S50 4.064 E14 22.645',
190 "50° 04.064' S, 014° 22.645' E"
192 post :search, :query => code
193 assert_response :success
194 assert_equal ['latlon' ,'osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
195 assert_nil @controller.params[:query]
196 assert_in_delta -50.06773, @controller.params[:lat]
197 assert_in_delta 14.37742, @controller.params[:lon]
202 # Test identification of lat/lon pairs using S/W with degrees/mins
203 def test_identify_latlon_sw_dm
205 'S 50° 04.064 W 014° 22.645',
206 "S 50° 04.064' W 014° 22.645",
207 "S 50° 04.064', W 014° 22.645'",
208 'S50° 04.064 W14° 22.645',
209 'S 50 04.064 W 014 22.645',
210 'S50 4.064 W14 22.645',
211 "50° 04.064' S, 014° 22.645' W"
213 post :search, :query => code
214 assert_response :success
215 assert_equal ['latlon' ,'osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
216 assert_nil @controller.params[:query]
217 assert_in_delta -50.06773, @controller.params[:lat]
218 assert_in_delta -14.37742, @controller.params[:lon]
223 # Test identification of lat/lon pairs using N/E with degrees/mins/secs
224 def test_identify_latlon_ne_dms
226 "N 50° 4' 03.828\" E 14° 22' 38.712\"",
227 "N 50° 4' 03.828\", E 14° 22' 38.712\"",
228 "N 50° 4′ 03.828″, E 14° 22′ 38.712″",
229 'N50 4 03.828 E14 22 38.712',
230 'N50 4 03.828, E14 22 38.712',
231 "50°4'3.828\"N 14°22'38.712\"E"
233 post :search, :query => code
234 assert_response :success
235 assert_equal ['latlon' ,'osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
236 assert_nil @controller.params[:query]
237 assert_in_delta 50.06773, @controller.params[:lat]
238 assert_in_delta 14.37742, @controller.params[:lon]
243 # Test identification of lat/lon pairs using N/W with degrees/mins/secs
244 def test_identify_latlon_nw_dms
246 "N 50° 4' 03.828\" W 14° 22' 38.712\"",
247 "N 50° 4' 03.828\", W 14° 22' 38.712\"",
248 "N 50° 4′ 03.828″, W 14° 22′ 38.712″",
249 'N50 4 03.828 W14 22 38.712',
250 'N50 4 03.828, W14 22 38.712',
251 "50°4'3.828\"N 14°22'38.712\"W"
253 post :search, :query => code
254 assert_response :success
255 assert_equal ['latlon' ,'osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
256 assert_nil @controller.params[:query]
257 assert_in_delta 50.06773, @controller.params[:lat]
258 assert_in_delta -14.37742, @controller.params[:lon]
263 # Test identification of lat/lon pairs using S/E with degrees/mins/secs
264 def test_identify_latlon_se_dms
266 "S 50° 4' 03.828\" E 14° 22' 38.712\"",
267 "S 50° 4' 03.828\", E 14° 22' 38.712\"",
268 "S 50° 4′ 03.828″, E 14° 22′ 38.712″",
269 'S50 4 03.828 E14 22 38.712',
270 'S50 4 03.828, E14 22 38.712',
271 "50°4'3.828\"S 14°22'38.712\"E"
273 post :search, :query => code
274 assert_response :success
275 assert_equal ['latlon' ,'osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
276 assert_nil @controller.params[:query]
277 assert_in_delta -50.06773, @controller.params[:lat]
278 assert_in_delta 14.37742, @controller.params[:lon]
283 # Test identification of lat/lon pairs using S/W with degrees/mins/secs
284 def test_identify_latlon_sw_dms
286 "S 50° 4' 03.828\" W 14° 22' 38.712\"",
287 "S 50° 4' 03.828\", W 14° 22' 38.712\"",
288 "S 50° 4′ 03.828″, W 14° 22′ 38.712″",
289 'S50 4 03.828 W14 22 38.712',
290 'S50 4 03.828, W14 22 38.712',
291 "50°4'3.828\"S 14°22'38.712\"W"
293 post :search, :query => code
294 assert_response :success
295 assert_equal ['latlon' ,'osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
296 assert_nil @controller.params[:query]
297 assert_in_delta -50.06773, @controller.params[:lat]
298 assert_in_delta -14.37742, @controller.params[:lon]
303 # Test identification of US zipcodes
304 def test_identify_us_postcode
309 post :search, query: code
310 assert_response :success
311 assert_equal ['us_postcode', 'osm_nominatim'], assigns(:sources)
316 # Test identification of UK postcodes using examples from
317 # http://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom
318 def test_identify_uk_postcode
327 post :search, query: code
328 assert_response :success
329 assert_equal ['uk_postcode', 'osm_nominatim'], assigns(:sources)
334 # Test identification of Canadian postcodes
335 def test_identify_ca_postcode
336 post :search, query: 'A1B 2C3'
337 assert_response :success
338 assert_equal ['ca_postcode', 'osm_nominatim'], assigns(:sources)
342 # Test identification fall through to the default case
343 def test_identify_default
344 post :search, query: 'foo bar baz'
345 assert_response :success
346 assert_equal ['osm_nominatim'], assigns(:sources)