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, :lat => 4, :lon => 5
95 assert_redirected_to :controller => :site, :action => :index, :anchor => 'map=5/4/5'
97 get :index, :lat => 4, :lon => 5, :zoom => 3
98 assert_redirected_to :controller => :site, :action => :index, :anchor => 'map=3/4/5'
100 get :index, :layers => 'T'
101 assert_redirected_to :controller => :site, :action => :index, :anchor => 'layers=T'
103 get :index, :notes => 'yes'
104 assert_redirected_to :controller => :site, :action => :index, :anchor => 'layers=N'
106 get :index, :lat => 4, :lon => 5, :zoom => 3, :layers => 'T'
107 assert_redirected_to :controller => :site, :action => :index, :anchor => 'map=3/4/5&layers=T'
110 # Test the permalink redirect
112 get :permalink, :code => 'wBz3--'
113 assert_response :redirect
114 assert_redirected_to :controller => :site, :action => :index, :anchor => 'map=3/4.8779296875/3.955078125'
116 get :permalink, :code => 'wBz3--', :m => ''
117 assert_response :redirect
118 assert_redirected_to :controller => :site, :action => :index, :mlat => '4.8779296875', :mlon => '3.955078125', :anchor => 'map=3/4.8779296875/3.955078125'
120 get :permalink, :code => 'wBz3--', :layers => 'T'
121 assert_response :redirect
122 assert_redirected_to :controller => :site, :action => :index, :anchor => 'map=3/4.8779296875/3.955078125&layers=T'
124 get :permalink, :code => 'wBz3--', :node => 1
125 assert_response :redirect
126 assert_redirected_to :controller => :browse, :action => :node, :id => 1, :anchor => 'map=3/4.8779296875/3.955078125'
128 get :permalink, :code => 'wBz3--', :way => 2
129 assert_response :redirect
130 assert_redirected_to :controller => :browse, :action => :way, :id => 2, :anchor => 'map=3/4.8779296875/3.955078125'
132 get :permalink, :code => 'wBz3--', :relation => 3
133 assert_response :redirect
134 assert_redirected_to :controller => :browse, :action => :relation, :id => 3, :anchor => 'map=3/4.8779296875/3.955078125'
136 get :permalink, :code => 'wBz3--', :changeset => 4
137 assert_response :redirect
138 assert_redirected_to :controller => :browse, :action => :changeset, :id => 4, :anchor => 'map=3/4.8779296875/3.955078125'
144 assert_response :success
145 assert_template "key"
146 assert_template :layout => false
149 # Test the edit page redirects when you aren't logged in
152 assert_response :redirect
153 assert_redirected_to :controller => :user, :action => :login, :referer => "/edit"
156 # Test the right editor gets used when the user hasn't set a preference
157 def test_edit_without_preference
158 get :edit, nil, { :user => users(:public_user).id }
159 assert_response :success
160 assert_template "edit"
161 assert_template :partial => "_#{DEFAULT_EDITOR}", :count => 1
164 # Test the right editor gets used when the user has set a preference
165 def test_edit_with_preference
166 user = users(:public_user)
167 user.preferred_editor = "id"
170 get :edit, nil, { :user => user.id }
171 assert_response :success
172 assert_template "edit"
173 assert_template :partial => "_id", :count => 1
175 user = users(:public_user)
176 user.preferred_editor = "potlatch2"
179 get :edit, nil, { :user => user.id }
180 assert_response :success
181 assert_template "edit"
182 assert_template :partial => "_potlatch2", :count => 1
184 user = users(:public_user)
185 user.preferred_editor = "potlatch"
188 get :edit, nil, { :user => user.id }
189 assert_response :success
190 assert_template "edit"
191 assert_template :partial => "_potlatch", :count => 1
193 user = users(:public_user)
194 user.preferred_editor = "remote"
197 get :edit, nil, { :user => user.id }
198 assert_response :success
199 assert_template "index"
202 # Test editing a specific node
203 def test_edit_with_node
204 user = users(:public_user)
205 node = current_nodes(:visible_node)
207 get :edit, { :node => node.id }, { :user => user.id }
208 assert_response :success
209 assert_template "edit"
210 assert_equal 1.0, assigns(:lat)
211 assert_equal 1.0, assigns(:lon)
212 assert_equal 18, assigns(:zoom)
215 # Test editing a specific way
216 def test_edit_with_way
217 user = users(:public_user)
218 way = current_ways(:visible_way)
220 get :edit, { :way => way.id }, { :user => user.id }
221 assert_response :success
222 assert_template "edit"
223 assert_equal 3.0, assigns(:lat)
224 assert_equal 3.0, assigns(:lon)
225 assert_equal 17, assigns(:zoom)
228 # Test editing a specific note
229 def test_edit_with_note
230 user = users(:public_user)
231 note = notes(:open_note)
233 get :edit, { :note => note.id }, { :user => user.id }
234 assert_response :success
235 assert_template "edit"
236 assert_equal 1.0, assigns(:lat)
237 assert_equal 1.0, assigns(:lon)
238 assert_equal 17, assigns(:zoom)
241 # Test editing a specific GPX trace
242 def test_edit_with_gpx
243 user = users(:public_user)
244 gpx = gpx_files(:public_trace_file)
246 get :edit, { :gpx => gpx.id }, { :user => user.id }
247 assert_response :success
248 assert_template "edit"
249 assert_equal 1.0, assigns(:lat)
250 assert_equal 1.0, assigns(:lon)
251 assert_equal 16, assigns(:zoom)
254 # Test the edit page redirects
255 def test_edit_redirect
256 get :edit, :lat => 4, :lon => 5
257 assert_redirected_to :controller => :site, :action => :edit, :anchor => 'map=5/4/5'
259 get :edit, :lat => 4, :lon => 5, :zoom => 3
260 assert_redirected_to :controller => :site, :action => :edit, :anchor => 'map=3/4/5'
262 get :edit, :lat => 4, :lon => 5, :zoom => 3, :editor => 'id'
263 assert_redirected_to :controller => :site, :action => :edit, :editor => 'id', :anchor => 'map=3/4/5'
266 # Test the copyright page
269 assert_response :success
270 assert_template "copyright"
273 # Test the welcome page
276 assert_response :redirect
277 assert_redirected_to :controller => :user, :action => :login, :referer => "/welcome"
279 get :welcome, nil, { :user => users(:public_user).id }
280 assert_response :success
281 assert_template "welcome"
284 # Test the fixthemap page
287 assert_response :success
288 assert_template "fixthemap"
294 assert_response :success
295 assert_template "help"
298 # Test the about page
301 assert_response :success
302 assert_template "about"
305 # Test the export page
308 assert_response :success
309 assert_template "export"
310 assert_template :layout => "map"
313 assert_response :success
314 assert_template "export"
315 assert_template :layout => "xhr"
318 # Test the offline page
321 assert_response :success
322 assert_template "offline"
325 # Test the rich text preview
327 xhr :post, :preview, :format => "html"
328 assert_response :success
330 xhr :post, :preview, :format => "markdown"
331 assert_response :success
333 xhr :post, :preview, :format => "text"
334 assert_response :success
339 get :id, nil, { :user => users(:public_user).id }
340 assert_response :success
342 assert_template :layout => false