3 class SiteControllerTest < ActionController::TestCase
9 Object.const_set("ID_KEY", client_applications(:oauth_web_app).key)
10 Object.const_set("POTLATCH2_KEY", client_applications(:oauth_web_app).key)
16 Object.send("remove_const", "ID_KEY")
17 Object.send("remove_const", "POTLATCH2_KEY")
21 # test all routes which lead to this controller
24 { :path => "/", :method => :get },
25 { :controller => "site", :action => "index" }
28 { :path => "/", :method => :post },
29 { :controller => "site", :action => "index" }
32 { :path => "/edit", :method => :get },
33 { :controller => "site", :action => "edit" }
36 { :controller => "site", :action => "edit", :format => "html" },
37 { :path => "/edit.html", :method => :get }
40 { :path => "/copyright", :method => :get },
41 { :controller => "site", :action => "copyright" }
44 { :path => "/copyright/locale", :method => :get },
45 { :controller => "site", :action => "copyright", :copyright_locale => "locale" }
48 { :path => "/welcome", :method => :get },
49 { :controller => "site", :action => "welcome" }
52 { :path => "/fixthemap", :method => :get },
53 { :controller => "site", :action => "fixthemap" }
56 { :path => "/export", :method => :get },
57 { :controller => "site", :action => "export" }
60 { :controller => "site", :action => "export", :format => "html" },
61 { :path => "/export.html", :method => :get }
64 { :path => "/offline", :method => :get },
65 { :controller => "site", :action => "offline" }
68 { :path => "/key", :method => :get },
69 { :controller => "site", :action => "key" }
72 { :path => "/go/shortcode", :method => :get },
73 { :controller => "site", :action => "permalink", :code => "shortcode" }
76 { :path => "/preview/formatname", :method => :post },
77 { :controller => "site", :action => "preview", :format => "formatname" }
80 { :path => "/id", :method => :get },
81 { :controller => "site", :action => "id" }
88 assert_response :success
89 assert_template "index"
92 # Test the index page redirects
93 def test_index_redirect
94 get :index, :node => 123
95 assert_redirected_to :controller => :browse, :action => :node, :id => 123
97 get :index, :way => 123
98 assert_redirected_to :controller => :browse, :action => :way, :id => 123
100 get :index, :relation => 123
101 assert_redirected_to :controller => :browse, :action => :relation, :id => 123
103 get :index, :note => 123
104 assert_redirected_to :controller => :browse, :action => :note, :id => 123
106 get :index, :query => "test"
107 assert_redirected_to :controller => :geocoder, :action => :search, :query => "test"
109 get :index, :lat => 4, :lon => 5
110 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=5/4/5"
112 get :index, :lat => 4, :lon => 5, :zoom => 3
113 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4/5"
115 get :index, :layers => "T"
116 assert_redirected_to :controller => :site, :action => :index, :anchor => "layers=T"
118 get :index, :notes => "yes"
119 assert_redirected_to :controller => :site, :action => :index, :anchor => "layers=N"
121 get :index, :lat => 4, :lon => 5, :zoom => 3, :layers => "T"
122 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4/5&layers=T"
125 # Test the permalink redirect
127 get :permalink, :code => "wBz3--"
128 assert_response :redirect
129 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4.8779296875/3.955078125"
131 get :permalink, :code => "wBz3--", :m => ""
132 assert_response :redirect
133 assert_redirected_to :controller => :site, :action => :index, :mlat => "4.8779296875", :mlon => "3.955078125", :anchor => "map=3/4.8779296875/3.955078125"
135 get :permalink, :code => "wBz3--", :layers => "T"
136 assert_response :redirect
137 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4.8779296875/3.955078125&layers=T"
139 get :permalink, :code => "wBz3--", :node => 1
140 assert_response :redirect
141 assert_redirected_to :controller => :browse, :action => :node, :id => 1, :anchor => "map=3/4.8779296875/3.955078125"
143 get :permalink, :code => "wBz3--", :way => 2
144 assert_response :redirect
145 assert_redirected_to :controller => :browse, :action => :way, :id => 2, :anchor => "map=3/4.8779296875/3.955078125"
147 get :permalink, :code => "wBz3--", :relation => 3
148 assert_response :redirect
149 assert_redirected_to :controller => :browse, :action => :relation, :id => 3, :anchor => "map=3/4.8779296875/3.955078125"
151 get :permalink, :code => "wBz3--", :changeset => 4
152 assert_response :redirect
153 assert_redirected_to :controller => :browse, :action => :changeset, :id => 4, :anchor => "map=3/4.8779296875/3.955078125"
159 assert_response :success
160 assert_template "key"
161 assert_template :layout => false
164 # Test the edit page redirects when you aren't logged in
167 assert_response :redirect
168 assert_redirected_to :controller => :user, :action => :login, :referer => "/edit"
171 # Test the right editor gets used when the user hasn't set a preference
172 def test_edit_without_preference
173 get :edit, nil, :user => users(:public_user).id
174 assert_response :success
175 assert_template "edit"
176 assert_template :partial => "_#{DEFAULT_EDITOR}", :count => 1
179 # Test the right editor gets used when the user has set a preference
180 def test_edit_with_preference
181 user = users(:public_user)
182 user.preferred_editor = "id"
185 get :edit, nil, :user => user.id
186 assert_response :success
187 assert_template "edit"
188 assert_template :partial => "_id", :count => 1
190 user = users(:public_user)
191 user.preferred_editor = "potlatch2"
194 get :edit, nil, :user => user.id
195 assert_response :success
196 assert_template "edit"
197 assert_template :partial => "_potlatch2", :count => 1
199 user = users(:public_user)
200 user.preferred_editor = "potlatch"
203 get :edit, nil, :user => user.id
204 assert_response :success
205 assert_template "edit"
206 assert_template :partial => "_potlatch", :count => 1
208 user = users(:public_user)
209 user.preferred_editor = "remote"
212 get :edit, nil, :user => user.id
213 assert_response :success
214 assert_template "index"
217 # Test the right editor gets used when the URL has an override
218 def test_edit_with_override
219 get :edit, { :editor => "id" }, { :user => users(:public_user).id }
220 assert_response :success
221 assert_template "edit"
222 assert_template :partial => "_id", :count => 1
224 get :edit, { :editor => "potlatch2" }, { :user => users(:public_user).id }
225 assert_response :success
226 assert_template "edit"
227 assert_template :partial => "_potlatch2", :count => 1
229 get :edit, { :editor => "potlatch" }, { :user => users(:public_user).id }
230 assert_response :success
231 assert_template "edit"
232 assert_template :partial => "_potlatch", :count => 1
234 get :edit, { :editor => "remote" }, { :user => users(:public_user).id }
235 assert_response :success
236 assert_template "index"
239 # Test editing a specific node
240 def test_edit_with_node
241 user = users(:public_user)
242 node = current_nodes(:visible_node)
244 get :edit, { :node => node.id }, { :user => user.id }
245 assert_response :success
246 assert_template "edit"
247 assert_equal 1.0, assigns(:lat)
248 assert_equal 1.0, assigns(:lon)
249 assert_equal 18, assigns(:zoom)
252 # Test editing a specific way
253 def test_edit_with_way
254 user = users(:public_user)
255 way = current_ways(:visible_way)
257 get :edit, { :way => way.id }, { :user => user.id }
258 assert_response :success
259 assert_template "edit"
260 assert_equal 3.0, assigns(:lat)
261 assert_equal 3.0, assigns(:lon)
262 assert_equal 17, assigns(:zoom)
265 # Test editing a specific note
266 def test_edit_with_note
267 user = users(:public_user)
268 note = create(:note) do |n|
269 n.comments.create(:author_id => user.id)
272 get :edit, { :note => note.id }, { :user => user.id }
273 assert_response :success
274 assert_template "edit"
275 assert_equal 1.0, assigns(:lat)
276 assert_equal 1.0, assigns(:lon)
277 assert_equal 17, assigns(:zoom)
280 # Test editing a specific GPX trace
281 def test_edit_with_gpx
282 user = users(:public_user)
283 gpx = create(:trace, :latitude => 1, :longitude => 1)
285 get :edit, { :gpx => gpx.id }, { :user => user.id }
286 assert_response :success
287 assert_template "edit"
288 assert_equal 1.0, assigns(:lat)
289 assert_equal 1.0, assigns(:lon)
290 assert_equal 16, assigns(:zoom)
293 # Test the edit page redirects
294 def test_edit_redirect
295 get :edit, :lat => 4, :lon => 5
296 assert_redirected_to :controller => :site, :action => :edit, :anchor => "map=5/4/5"
298 get :edit, :lat => 4, :lon => 5, :zoom => 3
299 assert_redirected_to :controller => :site, :action => :edit, :anchor => "map=3/4/5"
301 get :edit, :lat => 4, :lon => 5, :zoom => 3, :editor => "id"
302 assert_redirected_to :controller => :site, :action => :edit, :editor => "id", :anchor => "map=3/4/5"
305 # Test the copyright page
308 assert_response :success
309 assert_template "copyright"
312 # Test the welcome page
315 assert_response :redirect
316 assert_redirected_to :controller => :user, :action => :login, :referer => "/welcome"
318 get :welcome, nil, :user => users(:public_user).id
319 assert_response :success
320 assert_template "welcome"
323 # Test the fixthemap page
326 assert_response :success
327 assert_template "fixthemap"
333 assert_response :success
334 assert_template "help"
337 # Test the about page
340 assert_response :success
341 assert_template "about"
344 # Test the export page
347 assert_response :success
348 assert_template "export"
349 assert_template :layout => "map"
352 assert_response :success
353 assert_template "export"
354 assert_template :layout => "xhr"
357 # Test the offline page
360 assert_response :success
361 assert_template "offline"
364 # Test the rich text preview
366 xhr :post, :preview, :format => "html"
367 assert_response :success
369 xhr :post, :preview, :format => "markdown"
370 assert_response :success
372 xhr :post, :preview, :format => "text"
373 assert_response :success
378 get :id, nil, :user => users(:public_user).id
379 assert_response :success
381 assert_template :layout => false