3 class SiteControllerTest < ActionController::TestCase
9 Settings.id_key = create(:client_application).key
10 Settings.potlatch2_key = create(:client_application).key
19 Settings.potlatch2_key = nil
23 # test all routes which lead to this controller
26 { :path => "/", :method => :get },
27 { :controller => "site", :action => "index" }
30 { :path => "/", :method => :post },
31 { :controller => "site", :action => "index" }
34 { :path => "/edit", :method => :get },
35 { :controller => "site", :action => "edit" }
38 { :controller => "site", :action => "edit", :format => "html" },
39 { :path => "/edit.html", :method => :get }
42 { :path => "/copyright", :method => :get },
43 { :controller => "site", :action => "copyright" }
46 { :path => "/copyright/locale", :method => :get },
47 { :controller => "site", :action => "copyright", :copyright_locale => "locale" }
50 { :path => "/welcome", :method => :get },
51 { :controller => "site", :action => "welcome" }
54 { :path => "/fixthemap", :method => :get },
55 { :controller => "site", :action => "fixthemap" }
58 { :path => "/export", :method => :get },
59 { :controller => "site", :action => "export" }
62 { :controller => "site", :action => "export", :format => "html" },
63 { :path => "/export.html", :method => :get }
66 { :path => "/offline", :method => :get },
67 { :controller => "site", :action => "offline" }
70 { :path => "/key", :method => :get },
71 { :controller => "site", :action => "key" }
74 { :path => "/go/shortcode", :method => :get },
75 { :controller => "site", :action => "permalink", :code => "shortcode" }
78 { :path => "/preview/typename", :method => :post },
79 { :controller => "site", :action => "preview", :type => "typename" }
82 { :path => "/id", :method => :get },
83 { :controller => "site", :action => "id" }
90 assert_response :success
91 assert_template "index"
94 # Test the index page redirects
95 def test_index_redirect
96 get :index, :params => { :node => 123 }
97 assert_redirected_to :controller => :browse, :action => :node, :id => 123
99 get :index, :params => { :way => 123 }
100 assert_redirected_to :controller => :browse, :action => :way, :id => 123
102 get :index, :params => { :relation => 123 }
103 assert_redirected_to :controller => :browse, :action => :relation, :id => 123
105 get :index, :params => { :note => 123 }
106 assert_redirected_to :controller => :browse, :action => :note, :id => 123
108 get :index, :params => { :query => "test" }
109 assert_redirected_to :controller => :geocoder, :action => :search, :query => "test"
111 get :index, :params => { :lat => 4, :lon => 5 }
112 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=5/4/5"
114 get :index, :params => { :lat => 4, :lon => 5, :zoom => 3 }
115 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4/5"
117 get :index, :params => { :layers => "T" }
118 assert_redirected_to :controller => :site, :action => :index, :anchor => "layers=T"
120 get :index, :params => { :notes => "yes" }
121 assert_redirected_to :controller => :site, :action => :index, :anchor => "layers=N"
123 get :index, :params => { :lat => 4, :lon => 5, :zoom => 3, :layers => "T" }
124 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4/5&layers=T"
127 # Test the permalink redirect
129 get :permalink, :params => { :code => "wBz3--" }
130 assert_response :redirect
131 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4.8779296875/3.955078125"
133 get :permalink, :params => { :code => "wBz3--", :m => "" }
134 assert_response :redirect
135 assert_redirected_to :controller => :site, :action => :index, :mlat => "4.8779296875", :mlon => "3.955078125", :anchor => "map=3/4.8779296875/3.955078125"
137 get :permalink, :params => { :code => "wBz3--", :layers => "T" }
138 assert_response :redirect
139 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4.8779296875/3.955078125&layers=T"
141 get :permalink, :params => { :code => "wBz3--", :node => 1 }
142 assert_response :redirect
143 assert_redirected_to :controller => :browse, :action => :node, :id => 1, :anchor => "map=3/4.8779296875/3.955078125"
145 get :permalink, :params => { :code => "wBz3--", :way => 2 }
146 assert_response :redirect
147 assert_redirected_to :controller => :browse, :action => :way, :id => 2, :anchor => "map=3/4.8779296875/3.955078125"
149 get :permalink, :params => { :code => "wBz3--", :relation => 3 }
150 assert_response :redirect
151 assert_redirected_to :controller => :browse, :action => :relation, :id => 3, :anchor => "map=3/4.8779296875/3.955078125"
153 get :permalink, :params => { :code => "wBz3--", :changeset => 4 }
154 assert_response :redirect
155 assert_redirected_to :controller => :browse, :action => :changeset, :id => 4, :anchor => "map=3/4.8779296875/3.955078125"
160 get :key, :xhr => true
161 assert_response :success
162 assert_template "key"
163 assert_template :layout => false
166 # Test the edit page redirects when you aren't logged in
169 assert_response :redirect
170 assert_redirected_to :controller => :users, :action => :login, :referer => "/edit"
173 # Test the error when trying to edit without public edits
174 def test_edit_non_public
175 get :edit, :session => { :user => 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 get :edit, :session => { :user => create(:user) }
184 assert_response :success
185 assert_template "edit"
186 assert_template :partial => "_#{Settings.default_editor}", :count => 1
189 # Test the right editor gets used when the user has set a preference
190 def test_edit_with_preference
192 user.preferred_editor = "id"
195 get :edit, :session => { :user => user }
196 assert_response :success
197 assert_template "edit"
198 assert_template :partial => "_id", :count => 1
201 user.preferred_editor = "potlatch2"
204 get :edit, :session => { :user => user }
205 assert_response :success
206 assert_template "edit"
207 assert_template :partial => "_potlatch2", :count => 1
210 user.preferred_editor = "potlatch"
213 get :edit, :session => { :user => user }
214 assert_response :success
215 assert_template "edit"
216 assert_template :partial => "_potlatch", :count => 1
219 user.preferred_editor = "remote"
222 get :edit, :session => { :user => user }
223 assert_response :success
224 assert_template "index"
227 # Test the right editor gets used when the URL has an override
228 def test_edit_with_override
229 get :edit, :params => { :editor => "id" }, :session => { :user => create(:user) }
230 assert_response :success
231 assert_template "edit"
232 assert_template :partial => "_id", :count => 1
234 get :edit, :params => { :editor => "potlatch2" }, :session => { :user => create(:user) }
235 assert_response :success
236 assert_template "edit"
237 assert_template :partial => "_potlatch2", :count => 1
239 get :edit, :params => { :editor => "potlatch" }, :session => { :user => create(:user) }
240 assert_response :success
241 assert_template "edit"
242 assert_template :partial => "_potlatch", :count => 1
244 get :edit, :params => { :editor => "remote" }, :session => { :user => create(:user) }
245 assert_response :success
246 assert_template "index"
249 # Test editing a specific node
250 def test_edit_with_node
252 node = create(:node, :lat => 1.0, :lon => 1.0)
254 get :edit, :params => { :node => node.id }, :session => { :user => user }
255 assert_response :success
256 assert_template "edit"
257 assert_equal 1.0, assigns(:lat)
258 assert_equal 1.0, assigns(:lon)
259 assert_equal 18, assigns(:zoom)
262 # Test editing a specific way
263 def test_edit_with_way
265 node = create(:node, :lat => 3, :lon => 3)
267 create(:way_node, :node => node, :way => way)
269 get :edit, :params => { :way => way.id }, :session => { :user => user }
270 assert_response :success
271 assert_template "edit"
272 assert_equal 3.0, assigns(:lat)
273 assert_equal 3.0, assigns(:lon)
274 assert_equal 17, assigns(:zoom)
277 # Test editing a specific note
278 def test_edit_with_note
280 note = create(:note) do |n|
281 n.comments.create(:author_id => user.id)
284 get :edit, :params => { :note => note.id }, :session => { :user => user }
285 assert_response :success
286 assert_template "edit"
287 assert_equal 1.0, assigns(:lat)
288 assert_equal 1.0, assigns(:lon)
289 assert_equal 17, assigns(:zoom)
292 # Test editing a specific GPX trace
293 def test_edit_with_gpx
295 gpx = create(:trace, :latitude => 1, :longitude => 1)
297 get :edit, :params => { :gpx => gpx.id }, :session => { :user => user }
298 assert_response :success
299 assert_template "edit"
300 assert_equal 1.0, assigns(:lat)
301 assert_equal 1.0, assigns(:lon)
302 assert_equal 16, assigns(:zoom)
305 # Test the edit page redirects
306 def test_edit_redirect
307 get :edit, :params => { :lat => 4, :lon => 5 }
308 assert_redirected_to :controller => :site, :action => :edit, :anchor => "map=5/4/5"
310 get :edit, :params => { :lat => 4, :lon => 5, :zoom => 3 }
311 assert_redirected_to :controller => :site, :action => :edit, :anchor => "map=3/4/5"
313 get :edit, :params => { :lat => 4, :lon => 5, :zoom => 3, :editor => "id" }
314 assert_redirected_to :controller => :site, :action => :edit, :editor => "id", :anchor => "map=3/4/5"
317 # Test the copyright page
320 assert_response :success
321 assert_template "copyright"
324 # Test the welcome page
327 assert_response :redirect
328 assert_redirected_to :controller => :users, :action => :login, :referer => "/welcome"
330 get :welcome, :session => { :user => create(:user) }
331 assert_response :success
332 assert_template "welcome"
335 # Test the fixthemap page
338 assert_response :success
339 assert_template "fixthemap"
345 assert_response :success
346 assert_template "help"
349 # Test the about page
352 assert_response :success
353 assert_template "about"
356 # Test the export page
359 assert_response :success
360 assert_template "export"
361 assert_template :layout => "map"
363 get :export, :xhr => true
364 assert_response :success
365 assert_template "export"
366 assert_template :layout => "xhr"
369 # Test the offline page
372 assert_response :success
373 assert_template "offline"
376 # Test the rich text preview
378 post :preview, :xhr => true, :params => { :type => "html" }
379 assert_response :success
381 post :preview, :xhr => true, :params => { :type => "markdown" }
382 assert_response :success
384 post :preview, :xhr => true, :params => { :type => "text" }
385 assert_response :success
390 get :id, :session => { :user => create(:user) }
391 assert_response :success
393 assert_template :layout => false