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 = notes(:open_note)
270 get :edit, { :note => note.id }, { :user => user.id }
271 assert_response :success
272 assert_template "edit"
273 assert_equal 1.0, assigns(:lat)
274 assert_equal 1.0, assigns(:lon)
275 assert_equal 17, assigns(:zoom)
278 # Test editing a specific GPX trace
279 def test_edit_with_gpx
280 user = users(:public_user)
281 gpx = gpx_files(:public_trace_file)
283 get :edit, { :gpx => gpx.id }, { :user => user.id }
284 assert_response :success
285 assert_template "edit"
286 assert_equal 1.0, assigns(:lat)
287 assert_equal 1.0, assigns(:lon)
288 assert_equal 16, assigns(:zoom)
291 # Test the edit page redirects
292 def test_edit_redirect
293 get :edit, :lat => 4, :lon => 5
294 assert_redirected_to :controller => :site, :action => :edit, :anchor => "map=5/4/5"
296 get :edit, :lat => 4, :lon => 5, :zoom => 3
297 assert_redirected_to :controller => :site, :action => :edit, :anchor => "map=3/4/5"
299 get :edit, :lat => 4, :lon => 5, :zoom => 3, :editor => "id"
300 assert_redirected_to :controller => :site, :action => :edit, :editor => "id", :anchor => "map=3/4/5"
303 # Test the copyright page
306 assert_response :success
307 assert_template "copyright"
310 # Test the welcome page
313 assert_response :redirect
314 assert_redirected_to :controller => :user, :action => :login, :referer => "/welcome"
316 get :welcome, nil, :user => users(:public_user).id
317 assert_response :success
318 assert_template "welcome"
321 # Test the fixthemap page
324 assert_response :success
325 assert_template "fixthemap"
331 assert_response :success
332 assert_template "help"
335 # Test the about page
338 assert_response :success
339 assert_template "about"
342 # Test the export page
345 assert_response :success
346 assert_template "export"
347 assert_template :layout => "map"
350 assert_response :success
351 assert_template "export"
352 assert_template :layout => "xhr"
355 # Test the offline page
358 assert_response :success
359 assert_template "offline"
362 # Test the rich text preview
364 xhr :post, :preview, :format => "html"
365 assert_response :success
367 xhr :post, :preview, :format => "markdown"
368 assert_response :success
370 xhr :post, :preview, :format => "text"
371 assert_response :success
376 get :id, nil, :user => users(:public_user).id
377 assert_response :success
379 assert_template :layout => false