3 class SiteControllerTest < ActionController::TestCase
7 Object.const_set("ID_KEY", create(:client_application).key)
8 Object.const_set("POTLATCH2_KEY", create(:client_application).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/typename", :method => :post },
77 { :controller => "site", :action => "preview", :type => "typename" }
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, :params => { :node => 123 }
95 assert_redirected_to :controller => :browse, :action => :node, :id => 123
97 get :index, :params => { :way => 123 }
98 assert_redirected_to :controller => :browse, :action => :way, :id => 123
100 get :index, :params => { :relation => 123 }
101 assert_redirected_to :controller => :browse, :action => :relation, :id => 123
103 get :index, :params => { :note => 123 }
104 assert_redirected_to :controller => :browse, :action => :note, :id => 123
106 get :index, :params => { :query => "test" }
107 assert_redirected_to :controller => :geocoder, :action => :search, :query => "test"
109 get :index, :params => { :lat => 4, :lon => 5 }
110 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=5/4/5"
112 get :index, :params => { :lat => 4, :lon => 5, :zoom => 3 }
113 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4/5"
115 get :index, :params => { :layers => "T" }
116 assert_redirected_to :controller => :site, :action => :index, :anchor => "layers=T"
118 get :index, :params => { :notes => "yes" }
119 assert_redirected_to :controller => :site, :action => :index, :anchor => "layers=N"
121 get :index, :params => { :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, :params => { :code => "wBz3--" }
128 assert_response :redirect
129 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4.8779296875/3.955078125"
131 get :permalink, :params => { :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, :params => { :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, :params => { :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, :params => { :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, :params => { :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, :params => { :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"
158 get :key, :xhr => true
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 => :users, :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, :session => { :user => create(:user) }
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
182 user.preferred_editor = "id"
185 get :edit, :session => { :user => user }
186 assert_response :success
187 assert_template "edit"
188 assert_template :partial => "_id", :count => 1
191 user.preferred_editor = "potlatch2"
194 get :edit, :session => { :user => user }
195 assert_response :success
196 assert_template "edit"
197 assert_template :partial => "_potlatch2", :count => 1
200 user.preferred_editor = "potlatch"
203 get :edit, :session => { :user => user }
204 assert_response :success
205 assert_template "edit"
206 assert_template :partial => "_potlatch", :count => 1
209 user.preferred_editor = "remote"
212 get :edit, :session => { :user => user }
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, :params => { :editor => "id" }, :session => { :user => create(:user) }
220 assert_response :success
221 assert_template "edit"
222 assert_template :partial => "_id", :count => 1
224 get :edit, :params => { :editor => "potlatch2" }, :session => { :user => create(:user) }
225 assert_response :success
226 assert_template "edit"
227 assert_template :partial => "_potlatch2", :count => 1
229 get :edit, :params => { :editor => "potlatch" }, :session => { :user => create(:user) }
230 assert_response :success
231 assert_template "edit"
232 assert_template :partial => "_potlatch", :count => 1
234 get :edit, :params => { :editor => "remote" }, :session => { :user => create(:user) }
235 assert_response :success
236 assert_template "index"
239 # Test editing a specific node
240 def test_edit_with_node
242 node = create(:node, :lat => 1.0, :lon => 1.0)
244 get :edit, :params => { :node => node.id }, :session => { :user => user }
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
255 node = create(:node, :lat => 3, :lon => 3)
257 create(:way_node, :node => node, :way => way)
259 get :edit, :params => { :way => way.id }, :session => { :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
270 note = create(:note) do |n|
271 n.comments.create(:author_id => user.id)
274 get :edit, :params => { :note => note.id }, :session => { :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
285 gpx = create(:trace, :latitude => 1, :longitude => 1)
287 get :edit, :params => { :gpx => gpx.id }, :session => { :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, :params => { :lat => 4, :lon => 5 }
298 assert_redirected_to :controller => :site, :action => :edit, :anchor => "map=5/4/5"
300 get :edit, :params => { :lat => 4, :lon => 5, :zoom => 3 }
301 assert_redirected_to :controller => :site, :action => :edit, :anchor => "map=3/4/5"
303 get :edit, :params => { :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 => :users, :action => :login, :referer => "/welcome"
320 get :welcome, :session => { :user => create(: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"
353 get :export, :xhr => true
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 post :preview, :xhr => true, :params => { :type => "html" }
369 assert_response :success
371 post :preview, :xhr => true, :params => { :type => "markdown" }
372 assert_response :success
374 post :preview, :xhr => true, :params => { :type => "text" }
375 assert_response :success
380 get :id, :session => { :user => create(:user) }
381 assert_response :success
383 assert_template :layout => false