3 class SiteControllerTest < ActionDispatch::IntegrationTest
9 Settings.id_key = create(:client_application).key
19 # test all routes which lead to this controller
22 { :path => "/", :method => :get },
23 { :controller => "site", :action => "index" }
26 { :path => "/", :method => :post },
27 { :controller => "site", :action => "index" }
30 { :path => "/edit", :method => :get },
31 { :controller => "site", :action => "edit" }
34 { :controller => "site", :action => "edit", :format => "html" },
35 { :path => "/edit.html", :method => :get }
38 { :path => "/copyright", :method => :get },
39 { :controller => "site", :action => "copyright" }
42 { :path => "/copyright/locale", :method => :get },
43 { :controller => "site", :action => "copyright", :copyright_locale => "locale" }
46 { :path => "/welcome", :method => :get },
47 { :controller => "site", :action => "welcome" }
50 { :path => "/fixthemap", :method => :get },
51 { :controller => "site", :action => "fixthemap" }
54 { :path => "/help", :method => :get },
55 { :controller => "site", :action => "help" }
58 { :path => "/about", :method => :get },
59 { :controller => "site", :action => "about" }
62 { :path => "/about/locale", :method => :get },
63 { :controller => "site", :action => "about", :about_locale => "locale" }
66 { :path => "/export", :method => :get },
67 { :controller => "site", :action => "export" }
70 { :controller => "site", :action => "export", :format => "html" },
71 { :path => "/export.html", :method => :get }
74 { :path => "/offline", :method => :get },
75 { :controller => "site", :action => "offline" }
78 { :path => "/key", :method => :get },
79 { :controller => "site", :action => "key" }
82 { :path => "/go/shortcode", :method => :get },
83 { :controller => "site", :action => "permalink", :code => "shortcode" }
86 { :path => "/preview/typename", :method => :post },
87 { :controller => "site", :action => "preview", :type => "typename" }
90 { :path => "/id", :method => :get },
91 { :controller => "site", :action => "id" }
99 assert_response :success
100 assert_template "index"
103 # Test the index page redirects
104 def test_index_redirect
105 get root_path(:node => 123)
106 assert_redirected_to :controller => :browse, :action => :node, :id => 123
108 get root_path(:way => 123)
109 assert_redirected_to :controller => :browse, :action => :way, :id => 123
111 get root_path(:relation => 123)
112 assert_redirected_to :controller => :browse, :action => :relation, :id => 123
114 get root_path(:note => 123)
115 assert_redirected_to :controller => :browse, :action => :note, :id => 123
117 get root_path(:query => "test")
118 assert_redirected_to :controller => :geocoder, :action => :search, :query => "test"
120 get root_path(:lat => 4, :lon => 5)
121 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=5/4/5"
123 get root_path(:lat => 4, :lon => 5, :zoom => 3)
124 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4/5"
126 get root_path(:layers => "T")
127 assert_redirected_to :controller => :site, :action => :index, :anchor => "layers=T"
129 get root_path(:notes => "yes")
130 assert_redirected_to :controller => :site, :action => :index, :anchor => "layers=N"
132 get root_path(:lat => 4, :lon => 5, :zoom => 3, :layers => "T")
133 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4/5&layers=T"
136 # Test the permalink redirect
138 get permalink_path(:code => "wBz3--")
139 assert_response :redirect
140 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4.8779296875/3.955078125"
142 get permalink_path(:code => "wBz3--", :m => "")
143 assert_response :redirect
144 assert_redirected_to :controller => :site, :action => :index, :mlat => "4.8779296875", :mlon => "3.955078125", :anchor => "map=3/4.8779296875/3.955078125"
146 get permalink_path(:code => "wBz3--", :layers => "T")
147 assert_response :redirect
148 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4.8779296875/3.955078125&layers=T"
150 get permalink_path(:code => "wBz3--", :node => 1)
151 assert_response :redirect
152 assert_redirected_to :controller => :browse, :action => :node, :id => 1, :anchor => "map=3/4.8779296875/3.955078125"
154 get permalink_path(:code => "wBz3--", :way => 2)
155 assert_response :redirect
156 assert_redirected_to :controller => :browse, :action => :way, :id => 2, :anchor => "map=3/4.8779296875/3.955078125"
158 get permalink_path(:code => "wBz3--", :relation => 3)
159 assert_response :redirect
160 assert_redirected_to :controller => :browse, :action => :relation, :id => 3, :anchor => "map=3/4.8779296875/3.955078125"
162 get permalink_path(:code => "wBz3--", :changeset => 4)
163 assert_response :redirect
164 assert_redirected_to :controller => :browse, :action => :changeset, :id => 4, :anchor => "map=3/4.8779296875/3.955078125"
169 get key_path, :xhr => true
171 assert_response :success
172 assert_template "key"
173 assert_template :layout => false
176 # Test the edit page redirects when you aren't logged in
180 assert_response :redirect
181 assert_redirected_to :controller => :users, :action => :login, :referer => "/edit"
184 # Test the error when trying to edit without public edits
185 def test_edit_non_public
186 session_for(create(:user, :data_public => false))
190 assert_response :success
191 assert_template "edit"
192 assert_select "a[href='https://wiki.openstreetmap.org/wiki/Disabling_anonymous_edits']"
195 # Test the right editor gets used when the user hasn't set a preference
196 def test_edit_without_preference
197 session_for(create(:user))
201 assert_response :success
202 assert_template "edit"
203 assert_template :partial => "_#{Settings.default_editor}", :count => 1
206 # Test the right editor gets used when the user has set a preference
207 def test_edit_with_preference
209 user.preferred_editor = "id"
214 assert_response :success
215 assert_template "edit"
216 assert_template :partial => "_id", :count => 1
218 user.preferred_editor = "potlatch2"
222 assert_response :success
223 assert_template "edit"
224 assert_template :partial => "_potlatch2", :count => 1
226 user.preferred_editor = "potlatch"
230 assert_response :success
231 assert_template "edit"
232 assert_template :partial => "_potlatch", :count => 1
234 user.preferred_editor = "remote"
238 assert_response :success
239 assert_template "index"
242 # Test the right editor gets used when the URL has an override
243 def test_edit_with_override
244 session_for(create(:user))
246 get edit_path(:editor => "id")
247 assert_response :success
248 assert_template "edit"
249 assert_template :partial => "_id", :count => 1
251 get edit_path(:editor => "potlatch2")
252 assert_response :success
253 assert_template "edit"
254 assert_template :partial => "_potlatch2", :count => 1
256 get edit_path(:editor => "potlatch")
257 assert_response :success
258 assert_template "edit"
259 assert_template :partial => "_potlatch", :count => 1
261 get edit_path(:editor => "remote")
262 assert_response :success
263 assert_template "index"
266 # Test editing a specific node
267 def test_edit_with_node
269 node = create(:node, :lat => 1.0, :lon => 1.0)
272 get edit_path(:node => node.id)
274 assert_response :success
275 assert_template "edit"
276 assert_in_delta(1.0, assigns(:lat))
277 assert_in_delta(1.0, assigns(:lon))
278 assert_equal 18, assigns(:zoom)
281 # Test editing inaccessible nodes
282 def test_edit_with_inaccessible_nodes
284 deleted_node = create(:node, :lat => 1.0, :lon => 1.0, :visible => false)
287 get edit_path(:node => 99999)
288 assert_response :success
289 assert_template "edit"
290 assert_nil assigns(:lat)
291 assert_nil assigns(:lon)
292 assert_nil assigns(:zoom)
294 get edit_path(:node => deleted_node.id)
295 assert_response :success
296 assert_template "edit"
297 assert_nil assigns(:lat)
298 assert_nil assigns(:lon)
299 assert_nil assigns(:zoom)
302 # Test editing a specific way
303 def test_edit_with_way
305 node = create(:node, :lat => 3, :lon => 3)
307 create(:way_node, :node => node, :way => way)
310 get edit_path(:way => way.id)
311 assert_response :success
312 assert_template "edit"
313 assert_in_delta(3.0, assigns(:lat))
314 assert_in_delta(3.0, assigns(:lon))
315 assert_equal 17, assigns(:zoom)
318 # Test editing inaccessible ways
319 def test_edit_with_inaccessible_ways
321 deleted_way = create(:way, :visible => false)
324 get edit_path(:way => 99999)
325 assert_response :success
326 assert_template "edit"
327 assert_nil assigns(:lat)
328 assert_nil assigns(:lon)
329 assert_nil assigns(:zoom)
331 get edit_path(:way => deleted_way.id)
332 assert_response :success
333 assert_template "edit"
334 assert_nil assigns(:lat)
335 assert_nil assigns(:lon)
336 assert_nil assigns(:zoom)
339 # Test editing a specific note
340 def test_edit_with_note
342 note = create(:note) do |n|
343 n.comments.create(:author_id => user.id)
347 get edit_path(:note => note.id)
348 assert_response :success
349 assert_template "edit"
350 assert_in_delta(1.0, assigns(:lat))
351 assert_in_delta(1.0, assigns(:lon))
352 assert_equal 17, assigns(:zoom)
355 # Test editing inaccessible notes
356 def test_edit_with_inaccessible_notes
358 deleted_note = create(:note, :status => "hidden") do |n|
359 n.comments.create(:author_id => user.id)
363 get edit_path(:note => 99999)
364 assert_response :success
365 assert_template "edit"
366 assert_nil assigns(:lat)
367 assert_nil assigns(:lon)
368 assert_nil assigns(:zoom)
370 get edit_path(:note => deleted_note.id)
371 assert_response :success
372 assert_template "edit"
373 assert_nil assigns(:lat)
374 assert_nil assigns(:lon)
375 assert_nil assigns(:zoom)
378 # Test editing a specific GPX trace
379 def test_edit_with_gpx
381 gpx = create(:trace, :latitude => 1, :longitude => 1)
384 get edit_path(:gpx => gpx.id)
385 assert_response :success
386 assert_template "edit"
387 assert_in_delta(1.0, assigns(:lat))
388 assert_in_delta(1.0, assigns(:lon))
389 assert_equal 16, assigns(:zoom)
392 # Test editing inaccessible GPX traces
393 def test_edit_with_inaccessible_gpxes
395 deleted_gpx = create(:trace, :deleted, :latitude => 1, :longitude => 1)
396 private_gpx = create(:trace, :latitude => 1, :longitude => 1, :visibility => "private")
399 get edit_path(:gpx => 99999)
400 assert_response :success
401 assert_template "edit"
402 assert_nil assigns(:lat)
403 assert_nil assigns(:lon)
404 assert_nil assigns(:zoom)
406 get edit_path(:gpx => deleted_gpx.id)
407 assert_response :success
408 assert_template "edit"
409 assert_nil assigns(:lat)
410 assert_nil assigns(:lon)
411 assert_nil assigns(:zoom)
413 get edit_path(:gpx => private_gpx.id)
414 assert_response :success
415 assert_template "edit"
416 assert_nil assigns(:lat)
417 assert_nil assigns(:lon)
418 assert_nil assigns(:zoom)
421 # Test the edit page redirects
422 def test_edit_redirect
423 get edit_path(:lat => 4, :lon => 5)
424 assert_redirected_to :controller => :site, :action => :edit, :anchor => "map=5/4/5"
426 get edit_path(:lat => 4, :lon => 5, :zoom => 3)
427 assert_redirected_to :controller => :site, :action => :edit, :anchor => "map=3/4/5"
429 get edit_path(:lat => 4, :lon => 5, :zoom => 3, :editor => "id")
430 assert_redirected_to :controller => :site, :action => :edit, :editor => "id", :anchor => "map=3/4/5"
433 # Test the copyright page
436 assert_response :success
437 assert_template "copyright"
438 assert_select "div[lang='en'][dir='ltr']"
440 get copyright_path(:copyright_locale => "fr")
441 assert_response :success
442 assert_template "copyright"
443 assert_select "div[lang='fr'][dir='ltr']"
445 get copyright_path(:copyright_locale => "ar")
446 assert_response :success
447 assert_template "copyright"
448 assert_select "div[lang='ar'][dir='rtl']"
451 # Test the welcome page
454 assert_response :redirect
455 assert_redirected_to :controller => :users, :action => :login, :referer => "/welcome"
457 session_for(create(:user))
459 assert_response :success
460 assert_template "welcome"
463 # Test the fixthemap page
466 assert_response :success
467 assert_template "fixthemap"
473 assert_response :success
474 assert_template "help"
477 # Test the about page
480 assert_response :success
481 assert_template "about"
482 assert_select "div[lang='en'][dir='ltr']"
484 get about_path(:about_locale => "fr")
485 assert_response :success
486 assert_template "about"
487 assert_select "div[lang='fr'][dir='ltr']"
489 get about_path(:about_locale => "ar")
490 assert_response :success
491 assert_template "about"
492 assert_select "div[lang='ar'][dir='rtl']"
495 # Test the export page
498 assert_response :success
499 assert_template "export"
500 assert_template :layout => "map"
502 get export_path, :xhr => true
503 assert_response :success
504 assert_template "export"
505 assert_template :layout => "xhr"
508 # Test the offline page
511 assert_response :success
512 assert_template "offline"
515 # Test the rich text preview
517 post preview_path(:type => "html"), :xhr => true
518 assert_response :success
520 post preview_path(:type => "markdown"), :xhr => true
521 assert_response :success
523 post preview_path(:type => "text"), :xhr => true
524 assert_response :success
529 session_for(create(:user))
533 assert_response :success
535 assert_template :layout => false