3 class SiteControllerTest < ActionController::TestCase
9 Settings.id_key = create(:client_application).key
10 Settings.potlatch2_key = create(:client_application).key
19 Settings.potlatch2_key = nil
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/typename", :method => :post },
79 { :controller => "site", :action => "preview", :type => "typename" }
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, :params => { :node => 123 }
97 assert_redirected_to :controller => :browse, :action => :node, :id => 123
99 get :index, :params => { :way => 123 }
100 assert_redirected_to :controller => :browse, :action => :way, :id => 123
102 get :index, :params => { :relation => 123 }
103 assert_redirected_to :controller => :browse, :action => :relation, :id => 123
105 get :index, :params => { :note => 123 }
106 assert_redirected_to :controller => :browse, :action => :note, :id => 123
108 get :index, :params => { :query => "test" }
109 assert_redirected_to :controller => :geocoder, :action => :search, :query => "test"
111 get :index, :params => { :lat => 4, :lon => 5 }
112 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=5/4/5"
114 get :index, :params => { :lat => 4, :lon => 5, :zoom => 3 }
115 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4/5"
117 get :index, :params => { :layers => "T" }
118 assert_redirected_to :controller => :site, :action => :index, :anchor => "layers=T"
120 get :index, :params => { :notes => "yes" }
121 assert_redirected_to :controller => :site, :action => :index, :anchor => "layers=N"
123 get :index, :params => { :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, :params => { :code => "wBz3--" }
130 assert_response :redirect
131 assert_redirected_to :controller => :site, :action => :index, :anchor => "map=3/4.8779296875/3.955078125"
133 get :permalink, :params => { :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, :params => { :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, :params => { :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, :params => { :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, :params => { :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, :params => { :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"
160 get :key, :xhr => true
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 => :users, :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, :session => { :user => create(:user) }
176 assert_response :success
177 assert_template "edit"
178 assert_template :partial => "_#{Settings.default_editor}", :count => 1
181 # Test the right editor gets used when the user has set a preference
182 def test_edit_with_preference
184 user.preferred_editor = "id"
187 get :edit, :session => { :user => user }
188 assert_response :success
189 assert_template "edit"
190 assert_template :partial => "_id", :count => 1
193 user.preferred_editor = "potlatch2"
196 get :edit, :session => { :user => user }
197 assert_response :success
198 assert_template "edit"
199 assert_template :partial => "_potlatch2", :count => 1
202 user.preferred_editor = "potlatch"
205 get :edit, :session => { :user => user }
206 assert_response :success
207 assert_template "edit"
208 assert_template :partial => "_potlatch", :count => 1
211 user.preferred_editor = "remote"
214 get :edit, :session => { :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, :params => { :editor => "id" }, :session => { :user => create(:user) }
222 assert_response :success
223 assert_template "edit"
224 assert_template :partial => "_id", :count => 1
226 get :edit, :params => { :editor => "potlatch2" }, :session => { :user => create(:user) }
227 assert_response :success
228 assert_template "edit"
229 assert_template :partial => "_potlatch2", :count => 1
231 get :edit, :params => { :editor => "potlatch" }, :session => { :user => create(:user) }
232 assert_response :success
233 assert_template "edit"
234 assert_template :partial => "_potlatch", :count => 1
236 get :edit, :params => { :editor => "remote" }, :session => { :user => create(:user) }
237 assert_response :success
238 assert_template "index"
241 # Test editing a specific node
242 def test_edit_with_node
244 node = create(:node, :lat => 1.0, :lon => 1.0)
246 get :edit, :params => { :node => node.id }, :session => { :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
257 node = create(:node, :lat => 3, :lon => 3)
259 create(:way_node, :node => node, :way => way)
261 get :edit, :params => { :way => way.id }, :session => { :user => user }
262 assert_response :success
263 assert_template "edit"
264 assert_equal 3.0, assigns(:lat)
265 assert_equal 3.0, assigns(:lon)
266 assert_equal 17, assigns(:zoom)
269 # Test editing a specific note
270 def test_edit_with_note
272 note = create(:note) do |n|
273 n.comments.create(:author_id => user.id)
276 get :edit, :params => { :note => note.id }, :session => { :user => user }
277 assert_response :success
278 assert_template "edit"
279 assert_equal 1.0, assigns(:lat)
280 assert_equal 1.0, assigns(:lon)
281 assert_equal 17, assigns(:zoom)
284 # Test editing a specific GPX trace
285 def test_edit_with_gpx
287 gpx = create(:trace, :latitude => 1, :longitude => 1)
289 get :edit, :params => { :gpx => gpx.id }, :session => { :user => user }
290 assert_response :success
291 assert_template "edit"
292 assert_equal 1.0, assigns(:lat)
293 assert_equal 1.0, assigns(:lon)
294 assert_equal 16, assigns(:zoom)
297 # Test the edit page redirects
298 def test_edit_redirect
299 get :edit, :params => { :lat => 4, :lon => 5 }
300 assert_redirected_to :controller => :site, :action => :edit, :anchor => "map=5/4/5"
302 get :edit, :params => { :lat => 4, :lon => 5, :zoom => 3 }
303 assert_redirected_to :controller => :site, :action => :edit, :anchor => "map=3/4/5"
305 get :edit, :params => { :lat => 4, :lon => 5, :zoom => 3, :editor => "id" }
306 assert_redirected_to :controller => :site, :action => :edit, :editor => "id", :anchor => "map=3/4/5"
309 # Test the copyright page
312 assert_response :success
313 assert_template "copyright"
316 # Test the welcome page
319 assert_response :redirect
320 assert_redirected_to :controller => :users, :action => :login, :referer => "/welcome"
322 get :welcome, :session => { :user => create(:user) }
323 assert_response :success
324 assert_template "welcome"
327 # Test the fixthemap page
330 assert_response :success
331 assert_template "fixthemap"
337 assert_response :success
338 assert_template "help"
341 # Test the about page
344 assert_response :success
345 assert_template "about"
348 # Test the export page
351 assert_response :success
352 assert_template "export"
353 assert_template :layout => "map"
355 get :export, :xhr => true
356 assert_response :success
357 assert_template "export"
358 assert_template :layout => "xhr"
361 # Test the offline page
364 assert_response :success
365 assert_template "offline"
368 # Test the rich text preview
370 post :preview, :xhr => true, :params => { :type => "html" }
371 assert_response :success
373 post :preview, :xhr => true, :params => { :type => "markdown" }
374 assert_response :success
376 post :preview, :xhr => true, :params => { :type => "text" }
377 assert_response :success
382 get :id, :session => { :user => create(:user) }
383 assert_response :success
385 assert_template :layout => false