3 class SiteControllerTest < ActionController::TestCase
9 Object.const_set("ID_KEY", create(:client_application).key)
10 Object.const_set("POTLATCH2_KEY", create(:client_application).key)
18 Object.send("remove_const", "ID_KEY")
19 Object.send("remove_const", "POTLATCH2_KEY")
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/formatname", :method => :post },
79 { :controller => "site", :action => "preview", :format => "formatname" }
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, :node => 123
97 assert_redirected_to :controller => :browse, :action => :node, :id => 123
99 get :index, :way => 123
100 assert_redirected_to :controller => :browse, :action => :way, :id => 123
102 get :index, :relation => 123
103 assert_redirected_to :controller => :browse, :action => :relation, :id => 123
105 get :index, :note => 123
106 assert_redirected_to :controller => :browse, :action => :note, :id => 123
108 get :index, :query => "test"
109 assert_redirected_to :controller => :geocoder, :action => :search, :query => "test"
111 get :index, :lat => 4, :lon => 5
112 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=5/4/5"
114 get :index, :lat => 4, :lon => 5, :zoom => 3
115 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4/5"
117 get :index, :layers => "T"
118 assert_redirected_to :controller => :site, :action => :index, :anchor => "layers=T"
120 get :index, :notes => "yes"
121 assert_redirected_to :controller => :site, :action => :index, :anchor => "layers=N"
123 get :index, :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, :code => "wBz3--"
130 assert_response :redirect
131 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4.8779296875/3.955078125"
133 get :permalink, :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, :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, :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, :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, :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, :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"
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 => :user, :action => :login, :referer => "/edit"
173 # Test the right editor gets used when the user hasn't set a preference
174 def test_edit_without_preference
175 get :edit, nil, :user => users(:public_user)
176 assert_response :success
177 assert_template "edit"
178 assert_template :partial => "_#{DEFAULT_EDITOR}", :count => 1
181 # Test the right editor gets used when the user has set a preference
182 def test_edit_with_preference
183 user = users(:public_user)
184 user.preferred_editor = "id"
187 get :edit, nil, :user => user
188 assert_response :success
189 assert_template "edit"
190 assert_template :partial => "_id", :count => 1
192 user = users(:public_user)
193 user.preferred_editor = "potlatch2"
196 get :edit, nil, :user => user
197 assert_response :success
198 assert_template "edit"
199 assert_template :partial => "_potlatch2", :count => 1
201 user = users(:public_user)
202 user.preferred_editor = "potlatch"
205 get :edit, nil, :user => user
206 assert_response :success
207 assert_template "edit"
208 assert_template :partial => "_potlatch", :count => 1
210 user = users(:public_user)
211 user.preferred_editor = "remote"
214 get :edit, nil, :user => user
215 assert_response :success
216 assert_template "index"
219 # Test the right editor gets used when the URL has an override
220 def test_edit_with_override
221 get :edit, { :editor => "id" }, { :user => users(:public_user) }
222 assert_response :success
223 assert_template "edit"
224 assert_template :partial => "_id", :count => 1
226 get :edit, { :editor => "potlatch2" }, { :user => users(:public_user) }
227 assert_response :success
228 assert_template "edit"
229 assert_template :partial => "_potlatch2", :count => 1
231 get :edit, { :editor => "potlatch" }, { :user => users(:public_user) }
232 assert_response :success
233 assert_template "edit"
234 assert_template :partial => "_potlatch", :count => 1
236 get :edit, { :editor => "remote" }, { :user => users(:public_user) }
237 assert_response :success
238 assert_template "index"
241 # Test editing a specific node
242 def test_edit_with_node
243 user = users(:public_user)
244 node = current_nodes(:visible_node)
246 get :edit, { :node => node.id }, { :user => user }
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 18, assigns(:zoom)
254 # Test editing a specific way
255 def test_edit_with_way
256 user = users(:public_user)
257 way = current_ways(:visible_way)
259 get :edit, { :way => way.id }, { :user => user }
260 assert_response :success
261 assert_template "edit"
262 assert_equal 3.0, assigns(:lat)
263 assert_equal 3.0, assigns(:lon)
264 assert_equal 17, assigns(:zoom)
267 # Test editing a specific note
268 def test_edit_with_note
269 user = users(:public_user)
270 note = create(:note) do |n|
271 n.comments.create(:author_id => user.id)
274 get :edit, { :note => note.id }, { :user => user }
275 assert_response :success
276 assert_template "edit"
277 assert_equal 1.0, assigns(:lat)
278 assert_equal 1.0, assigns(:lon)
279 assert_equal 17, assigns(:zoom)
282 # Test editing a specific GPX trace
283 def test_edit_with_gpx
284 user = users(:public_user)
285 gpx = create(:trace, :latitude => 1, :longitude => 1)
287 get :edit, { :gpx => gpx.id }, { :user => user }
288 assert_response :success
289 assert_template "edit"
290 assert_equal 1.0, assigns(:lat)
291 assert_equal 1.0, assigns(:lon)
292 assert_equal 16, assigns(:zoom)
295 # Test the edit page redirects
296 def test_edit_redirect
297 get :edit, :lat => 4, :lon => 5
298 assert_redirected_to :controller => :site, :action => :edit, :anchor => "map=5/4/5"
300 get :edit, :lat => 4, :lon => 5, :zoom => 3
301 assert_redirected_to :controller => :site, :action => :edit, :anchor => "map=3/4/5"
303 get :edit, :lat => 4, :lon => 5, :zoom => 3, :editor => "id"
304 assert_redirected_to :controller => :site, :action => :edit, :editor => "id", :anchor => "map=3/4/5"
307 # Test the copyright page
310 assert_response :success
311 assert_template "copyright"
314 # Test the welcome page
317 assert_response :redirect
318 assert_redirected_to :controller => :user, :action => :login, :referer => "/welcome"
320 get :welcome, nil, :user => users(:public_user)
321 assert_response :success
322 assert_template "welcome"
325 # Test the fixthemap page
328 assert_response :success
329 assert_template "fixthemap"
335 assert_response :success
336 assert_template "help"
339 # Test the about page
342 assert_response :success
343 assert_template "about"
346 # Test the export page
349 assert_response :success
350 assert_template "export"
351 assert_template :layout => "map"
354 assert_response :success
355 assert_template "export"
356 assert_template :layout => "xhr"
359 # Test the offline page
362 assert_response :success
363 assert_template "offline"
366 # Test the rich text preview
368 xhr :post, :preview, :format => "html"
369 assert_response :success
371 xhr :post, :preview, :format => "markdown"
372 assert_response :success
374 xhr :post, :preview, :format => "text"
375 assert_response :success
380 get :id, nil, :user => users(:public_user)
381 assert_response :success
383 assert_template :layout => false