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_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4.8779296875/3.955078125"
127 get permalink_path(:code => "wBz3--", :m => "")
128 assert_redirected_to :controller => :site, :action => :index, :mlat => "4.8779296875", :mlon => "3.955078125", :anchor => "map=3/4.8779296875/3.955078125"
130 get permalink_path(:code => "wBz3--", :layers => "T")
131 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4.8779296875/3.955078125&layers=T"
133 get permalink_path(:code => "wBz3--", :node => 1)
134 assert_redirected_to :controller => :browse, :action => :node, :id => 1, :anchor => "map=3/4.8779296875/3.955078125"
136 get permalink_path(:code => "wBz3--", :way => 2)
137 assert_redirected_to :controller => :browse, :action => :way, :id => 2, :anchor => "map=3/4.8779296875/3.955078125"
139 get permalink_path(:code => "wBz3--", :relation => 3)
140 assert_redirected_to :controller => :browse, :action => :relation, :id => 3, :anchor => "map=3/4.8779296875/3.955078125"
142 get permalink_path(:code => "wBz3--", :changeset => 4)
143 assert_redirected_to changeset_path(:id => 4, :anchor => "map=3/4.8779296875/3.955078125")
148 get key_path, :xhr => true
150 assert_response :success
151 assert_template "key"
152 assert_template :layout => false
155 # Test the edit page redirects when you aren't logged in
159 assert_redirected_to login_path(:referer => "/edit")
162 # Test the error when trying to edit without public edits
163 def test_edit_non_public
164 session_for(create(:user, :data_public => false))
168 assert_response :success
169 assert_template "edit"
170 assert_select "a[href='https://wiki.openstreetmap.org/wiki/Disabling_anonymous_edits']"
173 # Test the right editor gets used when the user hasn't set a preference
174 def test_edit_without_preference
175 session_for(create(:user))
179 assert_response :success
180 assert_template "edit"
181 assert_template :partial => "_#{Settings.default_editor}", :count => 1
184 # Test the right editor gets used when the user has set a preference
185 def test_edit_with_preference
187 user.preferred_editor = "id"
192 assert_response :success
193 assert_template "edit"
194 assert_template :partial => "_id", :count => 1
196 user.preferred_editor = "potlatch2"
200 assert_response :success
201 assert_template "edit"
202 assert_template :partial => "_potlatch2", :count => 1
204 user.preferred_editor = "potlatch"
208 assert_response :success
209 assert_template "edit"
210 assert_template :partial => "_potlatch", :count => 1
212 user.preferred_editor = "remote"
216 assert_response :success
217 assert_template "index"
220 # Test the right editor gets used when the URL has an override
221 def test_edit_with_override
222 session_for(create(:user))
224 get edit_path(:editor => "id")
225 assert_response :success
226 assert_template "edit"
227 assert_template :partial => "_id", :count => 1
229 get edit_path(:editor => "potlatch2")
230 assert_response :success
231 assert_template "edit"
232 assert_template :partial => "_potlatch2", :count => 1
234 get edit_path(:editor => "potlatch")
235 assert_response :success
236 assert_template "edit"
237 assert_template :partial => "_potlatch", :count => 1
239 get edit_path(:editor => "remote")
240 assert_response :success
241 assert_template "index"
244 # Test editing a specific node
245 def test_edit_with_node
247 node = create(:node, :lat => 1.0, :lon => 1.0)
250 get edit_path(:node => node.id)
252 assert_response :success
253 assert_template "edit"
254 assert_in_delta(1.0, assigns(:lat))
255 assert_in_delta(1.0, assigns(:lon))
256 assert_equal 18, assigns(:zoom)
259 # Test editing inaccessible nodes
260 def test_edit_with_inaccessible_nodes
262 deleted_node = create(:node, :lat => 1.0, :lon => 1.0, :visible => false)
265 get edit_path(:node => 99999)
266 assert_response :success
267 assert_template "edit"
268 assert_nil assigns(:lat)
269 assert_nil assigns(:lon)
270 assert_nil assigns(:zoom)
272 get edit_path(:node => deleted_node.id)
273 assert_response :success
274 assert_template "edit"
275 assert_nil assigns(:lat)
276 assert_nil assigns(:lon)
277 assert_nil assigns(:zoom)
280 # Test editing a specific way
281 def test_edit_with_way
283 node = create(:node, :lat => 3, :lon => 3)
285 create(:way_node, :node => node, :way => way)
288 get edit_path(:way => way.id)
289 assert_response :success
290 assert_template "edit"
291 assert_in_delta(3.0, assigns(:lat))
292 assert_in_delta(3.0, assigns(:lon))
293 assert_equal 17, assigns(:zoom)
296 # Test editing inaccessible ways
297 def test_edit_with_inaccessible_ways
299 deleted_way = create(:way, :visible => false)
302 get edit_path(:way => 99999)
303 assert_response :success
304 assert_template "edit"
305 assert_nil assigns(:lat)
306 assert_nil assigns(:lon)
307 assert_nil assigns(:zoom)
309 get edit_path(:way => deleted_way.id)
310 assert_response :success
311 assert_template "edit"
312 assert_nil assigns(:lat)
313 assert_nil assigns(:lon)
314 assert_nil assigns(:zoom)
317 # Test editing a specific note
318 def test_edit_with_note
320 note = create(:note) do |n|
321 n.comments.create(:author_id => user.id)
325 get edit_path(:note => note.id)
326 assert_response :success
327 assert_template "edit"
328 assert_in_delta(1.0, assigns(:lat))
329 assert_in_delta(1.0, assigns(:lon))
330 assert_equal 17, assigns(:zoom)
333 # Test editing inaccessible notes
334 def test_edit_with_inaccessible_notes
336 deleted_note = create(:note, :status => "hidden") do |n|
337 n.comments.create(:author_id => user.id)
341 get edit_path(:note => 99999)
342 assert_response :success
343 assert_template "edit"
344 assert_nil assigns(:lat)
345 assert_nil assigns(:lon)
346 assert_nil assigns(:zoom)
348 get edit_path(:note => deleted_note.id)
349 assert_response :success
350 assert_template "edit"
351 assert_nil assigns(:lat)
352 assert_nil assigns(:lon)
353 assert_nil assigns(:zoom)
356 # Test editing a specific GPX trace
357 def test_edit_with_gpx
359 gpx = create(:trace, :latitude => 1, :longitude => 1)
362 get edit_path(:gpx => gpx.id)
363 assert_response :success
364 assert_template "edit"
365 assert_in_delta(1.0, assigns(:lat))
366 assert_in_delta(1.0, assigns(:lon))
367 assert_equal 16, assigns(:zoom)
370 # Test editing inaccessible GPX traces
371 def test_edit_with_inaccessible_gpxes
373 deleted_gpx = create(:trace, :deleted, :latitude => 1, :longitude => 1)
374 private_gpx = create(:trace, :latitude => 1, :longitude => 1, :visibility => "private")
377 get edit_path(:gpx => 99999)
378 assert_response :success
379 assert_template "edit"
380 assert_nil assigns(:lat)
381 assert_nil assigns(:lon)
382 assert_nil assigns(:zoom)
384 get edit_path(:gpx => deleted_gpx.id)
385 assert_response :success
386 assert_template "edit"
387 assert_nil assigns(:lat)
388 assert_nil assigns(:lon)
389 assert_nil assigns(:zoom)
391 get edit_path(:gpx => private_gpx.id)
392 assert_response :success
393 assert_template "edit"
394 assert_nil assigns(:lat)
395 assert_nil assigns(:lon)
396 assert_nil assigns(:zoom)
399 # Test the edit page redirects
400 def test_edit_redirect
401 get edit_path(:lat => 4, :lon => 5)
402 assert_redirected_to :controller => :site, :action => :edit, :anchor => "map=5/4/5"
404 get edit_path(:lat => 4, :lon => 5, :zoom => 3)
405 assert_redirected_to :controller => :site, :action => :edit, :anchor => "map=3/4/5"
407 get edit_path(:lat => 4, :lon => 5, :zoom => 3, :editor => "id")
408 assert_redirected_to :controller => :site, :action => :edit, :editor => "id", :anchor => "map=3/4/5"
411 # Test the copyright page
414 assert_response :success
415 assert_template "copyright"
416 assert_select "div[lang='en'][dir='ltr']"
418 get copyright_path(:copyright_locale => "fr")
419 assert_response :success
420 assert_template "copyright"
421 assert_select "div[lang='fr'][dir='ltr']"
423 get copyright_path(:copyright_locale => "ar")
424 assert_response :success
425 assert_template "copyright"
426 assert_select "div[lang='ar'][dir='rtl']"
429 # Test the welcome page
432 assert_redirected_to login_path(:referer => "/welcome")
434 session_for(create(:user))
436 assert_response :success
437 assert_template "welcome"
440 # Test the fixthemap page
443 assert_response :success
444 assert_template "fixthemap"
450 assert_response :success
451 assert_template "help"
454 # Test the about page
457 assert_response :success
458 assert_template "about"
459 assert_select "div[lang='en'][dir='ltr']"
461 get about_path(:about_locale => "fr")
462 assert_response :success
463 assert_template "about"
464 assert_select "div[lang='fr'][dir='ltr']"
466 get about_path(:about_locale => "ar")
467 assert_response :success
468 assert_template "about"
469 assert_select "div[lang='ar'][dir='rtl']"
471 # Page should still render even with incorrect locale
472 get about_path(:about_locale => "zzz")
473 assert_response :success
474 assert_template "about"
477 # Test the export page
480 assert_response :success
481 assert_template "export"
482 assert_template :layout => "map"
484 get export_path, :xhr => true
485 assert_response :success
486 assert_template "export"
487 assert_template :layout => "xhr"
490 # Test the offline page
493 assert_response :success
494 assert_select ".alert-warning"
497 # Test the rich text preview
499 post preview_path(:type => "html"), :xhr => true
500 assert_response :success
502 post preview_path(:type => "markdown"), :xhr => true
503 assert_response :success
505 post preview_path(:type => "text"), :xhr => true
506 assert_response :success
511 session_for(create(:user))
515 assert_response :success
517 assert_template :layout => false
520 # Test the id frame when not logged in
521 def test_id_without_login
524 assert_redirected_to login_path(:referer => "/id")