3 class SiteControllerTest < ActionDispatch::IntegrationTest
5 # test all routes which lead to this controller
8 { :path => "/", :method => :get },
9 { :controller => "site", :action => "index" }
12 { :path => "/", :method => :post },
13 { :controller => "site", :action => "index" }
16 { :path => "/edit", :method => :get },
17 { :controller => "site", :action => "edit" }
20 { :controller => "site", :action => "edit", :format => "html" },
21 { :path => "/edit.html", :method => :get }
24 { :path => "/copyright", :method => :get },
25 { :controller => "site", :action => "copyright" }
28 { :path => "/copyright/locale", :method => :get },
29 { :controller => "site", :action => "copyright", :copyright_locale => "locale" }
32 { :path => "/welcome", :method => :get },
33 { :controller => "site", :action => "welcome" }
36 { :path => "/fixthemap", :method => :get },
37 { :controller => "site", :action => "fixthemap" }
40 { :path => "/help", :method => :get },
41 { :controller => "site", :action => "help" }
44 { :path => "/about", :method => :get },
45 { :controller => "site", :action => "about" }
48 { :path => "/about/locale", :method => :get },
49 { :controller => "site", :action => "about", :about_locale => "locale" }
52 { :path => "/export", :method => :get },
53 { :controller => "site", :action => "export" }
56 { :controller => "site", :action => "export", :format => "html" },
57 { :path => "/export.html", :method => :get }
60 { :path => "/offline", :method => :get },
61 { :controller => "site", :action => "offline" }
64 { :path => "/key", :method => :get },
65 { :controller => "site", :action => "key" }
68 { :path => "/go/shortcode", :method => :get },
69 { :controller => "site", :action => "permalink", :code => "shortcode" }
72 { :path => "/preview/typename", :method => :post },
73 { :controller => "site", :action => "preview", :type => "typename" }
76 { :path => "/id", :method => :get },
77 { :controller => "site", :action => "id" }
85 assert_response :success
86 assert_template "index"
89 # Test the index page redirects
90 def test_index_redirect
91 get root_path(:node => 123)
92 assert_redirected_to :controller => :browse, :action => :node, :id => 123
94 get root_path(:way => 123)
95 assert_redirected_to :controller => :browse, :action => :way, :id => 123
97 get root_path(:relation => 123)
98 assert_redirected_to :controller => :browse, :action => :relation, :id => 123
100 get root_path(:note => 123)
101 assert_redirected_to :controller => :notes, :action => :show, :id => 123
103 get root_path(:query => "test")
104 assert_redirected_to :controller => :geocoder, :action => :search, :query => "test"
106 get root_path(:lat => 4, :lon => 5)
107 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=5/4/5"
109 get root_path(:lat => 4, :lon => 5, :zoom => 3)
110 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4/5"
112 get root_path(:layers => "T")
113 assert_redirected_to :controller => :site, :action => :index, :anchor => "layers=T"
115 get root_path(:notes => "yes")
116 assert_redirected_to :controller => :site, :action => :index, :anchor => "layers=N"
118 get root_path(:lat => 4, :lon => 5, :zoom => 3, :layers => "T")
119 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4/5&layers=T"
122 # Test the permalink redirect
124 get permalink_path(:code => "wBz3--")
125 assert_response :redirect
126 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4.8779296875/3.955078125"
128 get permalink_path(:code => "wBz3--", :m => "")
129 assert_response :redirect
130 assert_redirected_to :controller => :site, :action => :index, :mlat => "4.8779296875", :mlon => "3.955078125", :anchor => "map=3/4.8779296875/3.955078125"
132 get permalink_path(:code => "wBz3--", :layers => "T")
133 assert_response :redirect
134 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4.8779296875/3.955078125&layers=T"
136 get permalink_path(:code => "wBz3--", :node => 1)
137 assert_response :redirect
138 assert_redirected_to :controller => :browse, :action => :node, :id => 1, :anchor => "map=3/4.8779296875/3.955078125"
140 get permalink_path(:code => "wBz3--", :way => 2)
141 assert_response :redirect
142 assert_redirected_to :controller => :browse, :action => :way, :id => 2, :anchor => "map=3/4.8779296875/3.955078125"
144 get permalink_path(:code => "wBz3--", :relation => 3)
145 assert_response :redirect
146 assert_redirected_to :controller => :browse, :action => :relation, :id => 3, :anchor => "map=3/4.8779296875/3.955078125"
148 get permalink_path(:code => "wBz3--", :changeset => 4)
149 assert_response :redirect
150 assert_redirected_to changeset_path(:id => 4, :anchor => "map=3/4.8779296875/3.955078125")
155 get key_path, :xhr => true
157 assert_response :success
158 assert_template "key"
159 assert_template :layout => false
162 # Test the edit page redirects when you aren't logged in
166 assert_response :redirect
167 assert_redirected_to login_path(:referer => "/edit")
170 # Test the error when trying to edit without public edits
171 def test_edit_non_public
172 session_for(create(:user, :data_public => false))
176 assert_response :success
177 assert_template "edit"
178 assert_select "a[href='https://wiki.openstreetmap.org/wiki/Disabling_anonymous_edits']"
181 # Test the right editor gets used when the user hasn't set a preference
182 def test_edit_without_preference
183 session_for(create(:user))
187 assert_response :success
188 assert_template "edit"
189 assert_template :partial => "_#{Settings.default_editor}", :count => 1
192 # Test the right editor gets used when the user has set a preference
193 def test_edit_with_preference
195 user.preferred_editor = "id"
200 assert_response :success
201 assert_template "edit"
202 assert_template :partial => "_id", :count => 1
204 user.preferred_editor = "potlatch2"
208 assert_response :success
209 assert_template "edit"
210 assert_template :partial => "_potlatch2", :count => 1
212 user.preferred_editor = "potlatch"
216 assert_response :success
217 assert_template "edit"
218 assert_template :partial => "_potlatch", :count => 1
220 user.preferred_editor = "remote"
224 assert_response :success
225 assert_template "index"
228 # Test the right editor gets used when the URL has an override
229 def test_edit_with_override
230 session_for(create(:user))
232 get edit_path(:editor => "id")
233 assert_response :success
234 assert_template "edit"
235 assert_template :partial => "_id", :count => 1
237 get edit_path(:editor => "potlatch2")
238 assert_response :success
239 assert_template "edit"
240 assert_template :partial => "_potlatch2", :count => 1
242 get edit_path(:editor => "potlatch")
243 assert_response :success
244 assert_template "edit"
245 assert_template :partial => "_potlatch", :count => 1
247 get edit_path(:editor => "remote")
248 assert_response :success
249 assert_template "index"
252 # Test editing a specific node
253 def test_edit_with_node
255 node = create(:node, :lat => 1.0, :lon => 1.0)
258 get edit_path(:node => node.id)
260 assert_response :success
261 assert_template "edit"
262 assert_in_delta(1.0, assigns(:lat))
263 assert_in_delta(1.0, assigns(:lon))
264 assert_equal 18, assigns(:zoom)
267 # Test editing inaccessible nodes
268 def test_edit_with_inaccessible_nodes
270 deleted_node = create(:node, :lat => 1.0, :lon => 1.0, :visible => false)
273 get edit_path(:node => 99999)
274 assert_response :success
275 assert_template "edit"
276 assert_nil assigns(:lat)
277 assert_nil assigns(:lon)
278 assert_nil assigns(:zoom)
280 get edit_path(:node => deleted_node.id)
281 assert_response :success
282 assert_template "edit"
283 assert_nil assigns(:lat)
284 assert_nil assigns(:lon)
285 assert_nil assigns(:zoom)
288 # Test editing a specific way
289 def test_edit_with_way
291 node = create(:node, :lat => 3, :lon => 3)
293 create(:way_node, :node => node, :way => way)
296 get edit_path(:way => way.id)
297 assert_response :success
298 assert_template "edit"
299 assert_in_delta(3.0, assigns(:lat))
300 assert_in_delta(3.0, assigns(:lon))
301 assert_equal 17, assigns(:zoom)
304 # Test editing inaccessible ways
305 def test_edit_with_inaccessible_ways
307 deleted_way = create(:way, :visible => false)
310 get edit_path(:way => 99999)
311 assert_response :success
312 assert_template "edit"
313 assert_nil assigns(:lat)
314 assert_nil assigns(:lon)
315 assert_nil assigns(:zoom)
317 get edit_path(:way => deleted_way.id)
318 assert_response :success
319 assert_template "edit"
320 assert_nil assigns(:lat)
321 assert_nil assigns(:lon)
322 assert_nil assigns(:zoom)
325 # Test editing a specific note
326 def test_edit_with_note
328 note = create(:note) do |n|
329 n.comments.create(:author_id => user.id)
333 get edit_path(:note => note.id)
334 assert_response :success
335 assert_template "edit"
336 assert_in_delta(1.0, assigns(:lat))
337 assert_in_delta(1.0, assigns(:lon))
338 assert_equal 17, assigns(:zoom)
341 # Test editing inaccessible notes
342 def test_edit_with_inaccessible_notes
344 deleted_note = create(:note, :status => "hidden") do |n|
345 n.comments.create(:author_id => user.id)
349 get edit_path(:note => 99999)
350 assert_response :success
351 assert_template "edit"
352 assert_nil assigns(:lat)
353 assert_nil assigns(:lon)
354 assert_nil assigns(:zoom)
356 get edit_path(:note => deleted_note.id)
357 assert_response :success
358 assert_template "edit"
359 assert_nil assigns(:lat)
360 assert_nil assigns(:lon)
361 assert_nil assigns(:zoom)
364 # Test editing a specific GPX trace
365 def test_edit_with_gpx
367 gpx = create(:trace, :latitude => 1, :longitude => 1)
370 get edit_path(:gpx => gpx.id)
371 assert_response :success
372 assert_template "edit"
373 assert_in_delta(1.0, assigns(:lat))
374 assert_in_delta(1.0, assigns(:lon))
375 assert_equal 16, assigns(:zoom)
378 # Test editing inaccessible GPX traces
379 def test_edit_with_inaccessible_gpxes
381 deleted_gpx = create(:trace, :deleted, :latitude => 1, :longitude => 1)
382 private_gpx = create(:trace, :latitude => 1, :longitude => 1, :visibility => "private")
385 get edit_path(:gpx => 99999)
386 assert_response :success
387 assert_template "edit"
388 assert_nil assigns(:lat)
389 assert_nil assigns(:lon)
390 assert_nil assigns(:zoom)
392 get edit_path(:gpx => deleted_gpx.id)
393 assert_response :success
394 assert_template "edit"
395 assert_nil assigns(:lat)
396 assert_nil assigns(:lon)
397 assert_nil assigns(:zoom)
399 get edit_path(:gpx => private_gpx.id)
400 assert_response :success
401 assert_template "edit"
402 assert_nil assigns(:lat)
403 assert_nil assigns(:lon)
404 assert_nil assigns(:zoom)
407 # Test the edit page redirects
408 def test_edit_redirect
409 get edit_path(:lat => 4, :lon => 5)
410 assert_redirected_to :controller => :site, :action => :edit, :anchor => "map=5/4/5"
412 get edit_path(:lat => 4, :lon => 5, :zoom => 3)
413 assert_redirected_to :controller => :site, :action => :edit, :anchor => "map=3/4/5"
415 get edit_path(:lat => 4, :lon => 5, :zoom => 3, :editor => "id")
416 assert_redirected_to :controller => :site, :action => :edit, :editor => "id", :anchor => "map=3/4/5"
419 # Test the copyright page
422 assert_response :success
423 assert_template "copyright"
424 assert_select "div[lang='en'][dir='ltr']"
426 get copyright_path(:copyright_locale => "fr")
427 assert_response :success
428 assert_template "copyright"
429 assert_select "div[lang='fr'][dir='ltr']"
431 get copyright_path(:copyright_locale => "ar")
432 assert_response :success
433 assert_template "copyright"
434 assert_select "div[lang='ar'][dir='rtl']"
437 # Test the welcome page
440 assert_response :redirect
441 assert_redirected_to login_path(:referer => "/welcome")
443 session_for(create(:user))
445 assert_response :success
446 assert_template "welcome"
449 # Test the fixthemap page
452 assert_response :success
453 assert_template "fixthemap"
459 assert_response :success
460 assert_template "help"
463 # Test the about page
466 assert_response :success
467 assert_template "about"
468 assert_select "div[lang='en'][dir='ltr']"
470 get about_path(:about_locale => "fr")
471 assert_response :success
472 assert_template "about"
473 assert_select "div[lang='fr'][dir='ltr']"
475 get about_path(:about_locale => "ar")
476 assert_response :success
477 assert_template "about"
478 assert_select "div[lang='ar'][dir='rtl']"
480 # Page should still render even with incorrect locale
481 get about_path(:about_locale => "zzz")
482 assert_response :success
483 assert_template "about"
486 # Test the export page
489 assert_response :success
490 assert_template "export"
491 assert_template :layout => "map"
493 get export_path, :xhr => true
494 assert_response :success
495 assert_template "export"
496 assert_template :layout => "xhr"
499 # Test the offline page
502 assert_response :success
503 assert_select ".alert-warning"
506 # Test the rich text preview
508 post preview_path(:type => "html"), :xhr => true
509 assert_response :success
511 post preview_path(:type => "markdown"), :xhr => true
512 assert_response :success
514 post preview_path(:type => "text"), :xhr => true
515 assert_response :success
520 session_for(create(:user))
524 assert_response :success
526 assert_template :layout => false
529 # Test the id frame when not logged in
530 def test_id_without_login
533 assert_response :redirect
534 assert_redirected_to login_path(:referer => "/id")