Mercurial > hg > soundsoftware-site
comparison test/functional/.svn/text-base/wiki_controller_test.rb.svn-base @ 441:cbce1fd3b1b7 redmine-1.2
Update to Redmine 1.2-stable branch (Redmine SVN rev 6000)
author | Chris Cannam |
---|---|
date | Mon, 06 Jun 2011 14:24:13 +0100 |
parents | 8661b858af72 |
children | 0c939c159af4 |
comparison
equal
deleted
inserted
replaced
245:051f544170fe | 441:cbce1fd3b1b7 |
---|---|
1 # redMine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2007 Jean-Philippe Lang | 2 # Copyright (C) 2006-2011 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
8 # | 8 # |
9 # This program is distributed in the hope that it will be useful, | 9 # This program is distributed in the hope that it will be useful, |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 # GNU General Public License for more details. | 12 # GNU General Public License for more details. |
13 # | 13 # |
14 # You should have received a copy of the GNU General Public License | 14 # You should have received a copy of the GNU General Public License |
15 # along with this program; if not, write to the Free Software | 15 # along with this program; if not, write to the Free Software |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | 17 |
18 require File.expand_path('../../test_helper', __FILE__) | 18 require File.expand_path('../../test_helper', __FILE__) |
21 # Re-raise errors caught by the controller. | 21 # Re-raise errors caught by the controller. |
22 class WikiController; def rescue_action(e) raise e end; end | 22 class WikiController; def rescue_action(e) raise e end; end |
23 | 23 |
24 class WikiControllerTest < ActionController::TestCase | 24 class WikiControllerTest < ActionController::TestCase |
25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, :attachments | 25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, :attachments |
26 | 26 |
27 def setup | 27 def setup |
28 @controller = WikiController.new | 28 @controller = WikiController.new |
29 @request = ActionController::TestRequest.new | 29 @request = ActionController::TestRequest.new |
30 @response = ActionController::TestResponse.new | 30 @response = ActionController::TestResponse.new |
31 User.current = nil | 31 User.current = nil |
32 end | 32 end |
33 | 33 |
34 def test_show_start_page | 34 def test_show_start_page |
35 get :show, :project_id => 'ecookbook' | 35 get :show, :project_id => 'ecookbook' |
36 assert_response :success | 36 assert_response :success |
37 assert_template 'show' | 37 assert_template 'show' |
38 assert_tag :tag => 'h1', :content => /CookBook documentation/ | 38 assert_tag :tag => 'h1', :content => /CookBook documentation/ |
41 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' }, | 41 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' }, |
42 :child => { :tag => 'li', | 42 :child => { :tag => 'li', |
43 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' }, | 43 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' }, |
44 :content => 'Page with an inline image' } } | 44 :content => 'Page with an inline image' } } |
45 end | 45 end |
46 | 46 |
47 def test_show_page_with_name | 47 def test_show_page_with_name |
48 get :show, :project_id => 1, :id => 'Another_page' | 48 get :show, :project_id => 1, :id => 'Another_page' |
49 assert_response :success | 49 assert_response :success |
50 assert_template 'show' | 50 assert_template 'show' |
51 assert_tag :tag => 'h1', :content => /Another page/ | 51 assert_tag :tag => 'h1', :content => /Another page/ |
52 # Included page with an inline image | 52 # Included page with an inline image |
53 assert_tag :tag => 'p', :content => /This is an inline image/ | 53 assert_tag :tag => 'p', :content => /This is an inline image/ |
54 assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3', | 54 assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3', |
55 :alt => 'This is a logo' } | 55 :alt => 'This is a logo' } |
56 end | 56 end |
57 | 57 |
58 def test_show_redirected_page | |
59 WikiRedirect.create!(:wiki_id => 1, :title => 'Old_title', :redirects_to => 'Another_page') | |
60 | |
61 get :show, :project_id => 'ecookbook', :id => 'Old_title' | |
62 assert_redirected_to '/projects/ecookbook/wiki/Another_page' | |
63 end | |
64 | |
58 def test_show_with_sidebar | 65 def test_show_with_sidebar |
59 page = Project.find(1).wiki.pages.new(:title => 'Sidebar') | 66 page = Project.find(1).wiki.pages.new(:title => 'Sidebar') |
60 page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar') | 67 page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar') |
61 page.save! | 68 page.save! |
62 | 69 |
63 get :show, :project_id => 1, :id => 'Another_page' | 70 get :show, :project_id => 1, :id => 'Another_page' |
64 assert_response :success | 71 assert_response :success |
65 assert_tag :tag => 'div', :attributes => {:id => 'sidebar'}, | 72 assert_tag :tag => 'div', :attributes => {:id => 'sidebar'}, |
66 :content => /Side bar content for test_show_with_sidebar/ | 73 :content => /Side bar content for test_show_with_sidebar/ |
67 end | 74 end |
68 | 75 |
69 def test_show_unexistent_page_without_edit_right | 76 def test_show_unexistent_page_without_edit_right |
70 get :show, :project_id => 1, :id => 'Unexistent page' | 77 get :show, :project_id => 1, :id => 'Unexistent page' |
71 assert_response 404 | 78 assert_response 404 |
72 end | 79 end |
73 | 80 |
74 def test_show_unexistent_page_with_edit_right | 81 def test_show_unexistent_page_with_edit_right |
75 @request.session[:user_id] = 2 | 82 @request.session[:user_id] = 2 |
76 get :show, :project_id => 1, :id => 'Unexistent page' | 83 get :show, :project_id => 1, :id => 'Unexistent page' |
77 assert_response :success | 84 assert_response :success |
78 assert_template 'edit' | 85 assert_template 'edit' |
79 end | 86 end |
80 | 87 |
81 def test_create_page | 88 def test_create_page |
82 @request.session[:user_id] = 2 | 89 @request.session[:user_id] = 2 |
83 put :update, :project_id => 1, | 90 put :update, :project_id => 1, |
84 :id => 'New page', | 91 :id => 'New page', |
85 :content => {:comments => 'Created the page', | 92 :content => {:comments => 'Created the page', |
89 page = Project.find(1).wiki.find_page('New page') | 96 page = Project.find(1).wiki.find_page('New page') |
90 assert !page.new_record? | 97 assert !page.new_record? |
91 assert_not_nil page.content | 98 assert_not_nil page.content |
92 assert_equal 'Created the page', page.content.comments | 99 assert_equal 'Created the page', page.content.comments |
93 end | 100 end |
94 | 101 |
95 def test_create_page_with_attachments | 102 def test_create_page_with_attachments |
96 @request.session[:user_id] = 2 | 103 @request.session[:user_id] = 2 |
97 assert_difference 'WikiPage.count' do | 104 assert_difference 'WikiPage.count' do |
98 assert_difference 'Attachment.count' do | 105 assert_difference 'Attachment.count' do |
99 put :update, :project_id => 1, | 106 put :update, :project_id => 1, |
123 } | 130 } |
124 end | 131 end |
125 end | 132 end |
126 end | 133 end |
127 assert_redirected_to '/projects/ecookbook/wiki/Another_page' | 134 assert_redirected_to '/projects/ecookbook/wiki/Another_page' |
128 | 135 |
129 page = Wiki.find(1).pages.find_by_title('Another_page') | 136 page = Wiki.find(1).pages.find_by_title('Another_page') |
130 assert_equal "edited", page.content.text | 137 assert_equal "edited", page.content.text |
131 assert_equal 2, page.content.version | 138 assert_equal 2, page.content.version |
132 assert_equal "my comments", page.content.comments | 139 assert_equal "my comments", page.content.comments |
133 end | 140 end |
147 end | 154 end |
148 end | 155 end |
149 end | 156 end |
150 assert_response :success | 157 assert_response :success |
151 assert_template 'edit' | 158 assert_template 'edit' |
152 | 159 |
153 assert_error_tag :descendant => {:content => /Comment is too long/} | 160 assert_error_tag :descendant => {:content => /Comment is too long/} |
154 assert_tag :tag => 'textarea', :attributes => {:id => 'content_text'}, :content => 'edited' | 161 assert_tag :tag => 'textarea', :attributes => {:id => 'content_text'}, :content => 'edited' |
155 assert_tag :tag => 'input', :attributes => {:id => 'content_version', :value => '1'} | 162 assert_tag :tag => 'input', :attributes => {:id => 'content_version', :value => '1'} |
156 end | 163 end |
157 | 164 |
165 def test_update_stale_page_should_not_raise_an_error | |
166 @request.session[:user_id] = 2 | |
167 c = Wiki.find(1).find_page('Another_page').content | |
168 c.text = 'Previous text' | |
169 c.save! | |
170 assert_equal 2, c.version | |
171 | |
172 assert_no_difference 'WikiPage.count' do | |
173 assert_no_difference 'WikiContent.count' do | |
174 assert_no_difference 'WikiContent::Version.count' do | |
175 put :update, :project_id => 1, | |
176 :id => 'Another_page', | |
177 :content => { | |
178 :comments => 'My comments', | |
179 :text => 'Text should not be lost', | |
180 :version => 1 | |
181 } | |
182 end | |
183 end | |
184 end | |
185 assert_response :success | |
186 assert_template 'edit' | |
187 assert_tag :div, | |
188 :attributes => { :class => /error/ }, | |
189 :content => /Data has been updated by another user/ | |
190 assert_tag 'textarea', | |
191 :attributes => { :name => 'content[text]' }, | |
192 :content => /Text should not be lost/ | |
193 assert_tag 'input', | |
194 :attributes => { :name => 'content[comments]', :value => 'My comments' } | |
195 | |
196 c.reload | |
197 assert_equal 'Previous text', c.text | |
198 assert_equal 2, c.version | |
199 end | |
200 | |
158 def test_preview | 201 def test_preview |
159 @request.session[:user_id] = 2 | 202 @request.session[:user_id] = 2 |
160 xhr :post, :preview, :project_id => 1, :id => 'CookBook_documentation', | 203 xhr :post, :preview, :project_id => 1, :id => 'CookBook_documentation', |
161 :content => { :comments => '', | 204 :content => { :comments => '', |
162 :text => 'this is a *previewed text*', | 205 :text => 'this is a *previewed text*', |
163 :version => 3 } | 206 :version => 3 } |
164 assert_response :success | 207 assert_response :success |
165 assert_template 'common/_preview' | 208 assert_template 'common/_preview' |
166 assert_tag :tag => 'strong', :content => /previewed text/ | 209 assert_tag :tag => 'strong', :content => /previewed text/ |
167 end | 210 end |
168 | 211 |
169 def test_preview_new_page | 212 def test_preview_new_page |
170 @request.session[:user_id] = 2 | 213 @request.session[:user_id] = 2 |
171 xhr :post, :preview, :project_id => 1, :id => 'New page', | 214 xhr :post, :preview, :project_id => 1, :id => 'New page', |
172 :content => { :text => 'h1. New page', | 215 :content => { :text => 'h1. New page', |
173 :comments => '', | 216 :comments => '', |
174 :version => 0 } | 217 :version => 0 } |
175 assert_response :success | 218 assert_response :success |
176 assert_template 'common/_preview' | 219 assert_template 'common/_preview' |
177 assert_tag :tag => 'h1', :content => /New page/ | 220 assert_tag :tag => 'h1', :content => /New page/ |
178 end | 221 end |
179 | 222 |
180 def test_history | 223 def test_history |
181 get :history, :project_id => 1, :id => 'CookBook_documentation' | 224 get :history, :project_id => 1, :id => 'CookBook_documentation' |
182 assert_response :success | 225 assert_response :success |
183 assert_template 'history' | 226 assert_template 'history' |
184 assert_not_nil assigns(:versions) | 227 assert_not_nil assigns(:versions) |
192 assert_template 'history' | 235 assert_template 'history' |
193 assert_not_nil assigns(:versions) | 236 assert_not_nil assigns(:versions) |
194 assert_equal 1, assigns(:versions).size | 237 assert_equal 1, assigns(:versions).size |
195 assert_select "input[type=submit][name=commit]", false | 238 assert_select "input[type=submit][name=commit]", false |
196 end | 239 end |
197 | 240 |
198 def test_diff | 241 def test_diff |
199 get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => 2, :version_from => 1 | 242 get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => 2, :version_from => 1 |
200 assert_response :success | 243 assert_response :success |
201 assert_template 'diff' | 244 assert_template 'diff' |
202 assert_tag :tag => 'span', :attributes => { :class => 'diff_in'}, | 245 assert_tag :tag => 'span', :attributes => { :class => 'diff_in'}, |
203 :content => /updated/ | 246 :content => /updated/ |
204 end | 247 end |
205 | 248 |
206 def test_annotate | 249 def test_annotate |
207 get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2 | 250 get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2 |
208 assert_response :success | 251 assert_response :success |
209 assert_template 'annotate' | 252 assert_template 'annotate' |
210 # Line 1 | 253 # Line 1 |
228 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}} | 271 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}} |
229 assert_no_tag 'option', | 272 assert_no_tag 'option', |
230 :attributes => {:selected => 'selected'}, | 273 :attributes => {:selected => 'selected'}, |
231 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}} | 274 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}} |
232 end | 275 end |
233 | 276 |
234 def test_get_rename_child_page | 277 def test_get_rename_child_page |
235 @request.session[:user_id] = 2 | 278 @request.session[:user_id] = 2 |
236 get :rename, :project_id => 1, :id => 'Child_1' | 279 get :rename, :project_id => 1, :id => 'Child_1' |
237 assert_response :success | 280 assert_response :success |
238 assert_template 'rename' | 281 assert_template 'rename' |
246 :parent => { | 289 :parent => { |
247 :tag => 'select', | 290 :tag => 'select', |
248 :attributes => {:name => 'wiki_page[parent_id]'} | 291 :attributes => {:name => 'wiki_page[parent_id]'} |
249 } | 292 } |
250 end | 293 end |
251 | 294 |
252 def test_rename_with_redirect | 295 def test_rename_with_redirect |
253 @request.session[:user_id] = 2 | 296 @request.session[:user_id] = 2 |
254 post :rename, :project_id => 1, :id => 'Another_page', | 297 post :rename, :project_id => 1, :id => 'Another_page', |
255 :wiki_page => { :title => 'Another renamed page', | 298 :wiki_page => { :title => 'Another renamed page', |
256 :redirect_existing_links => 1 } | 299 :redirect_existing_links => 1 } |
269 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page' | 312 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page' |
270 wiki = Project.find(1).wiki | 313 wiki = Project.find(1).wiki |
271 # Check that there's no redirects | 314 # Check that there's no redirects |
272 assert_nil wiki.find_page('Another page') | 315 assert_nil wiki.find_page('Another page') |
273 end | 316 end |
274 | 317 |
275 def test_rename_with_parent_assignment | 318 def test_rename_with_parent_assignment |
276 @request.session[:user_id] = 2 | 319 @request.session[:user_id] = 2 |
277 post :rename, :project_id => 1, :id => 'Another_page', | 320 post :rename, :project_id => 1, :id => 'Another_page', |
278 :wiki_page => { :title => 'Another page', :redirect_existing_links => "0", :parent_id => '4' } | 321 :wiki_page => { :title => 'Another page', :redirect_existing_links => "0", :parent_id => '4' } |
279 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page' | 322 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page' |
285 post :rename, :project_id => 1, :id => 'Child_1', | 328 post :rename, :project_id => 1, :id => 'Child_1', |
286 :wiki_page => { :title => 'Child 1', :redirect_existing_links => "0", :parent_id => '' } | 329 :wiki_page => { :title => 'Child 1', :redirect_existing_links => "0", :parent_id => '' } |
287 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Child_1' | 330 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Child_1' |
288 assert_nil WikiPage.find_by_title('Child_1').parent | 331 assert_nil WikiPage.find_by_title('Child_1').parent |
289 end | 332 end |
290 | 333 |
291 def test_destroy_child | 334 def test_destroy_child |
292 @request.session[:user_id] = 2 | 335 @request.session[:user_id] = 2 |
293 delete :destroy, :project_id => 1, :id => 'Child_1' | 336 delete :destroy, :project_id => 1, :id => 'Child_1' |
294 assert_redirected_to :action => 'index', :project_id => 'ecookbook' | 337 assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
295 end | 338 end |
296 | 339 |
297 def test_destroy_parent | 340 def test_destroy_parent |
298 @request.session[:user_id] = 2 | 341 @request.session[:user_id] = 2 |
299 assert_no_difference('WikiPage.count') do | 342 assert_no_difference('WikiPage.count') do |
300 delete :destroy, :project_id => 1, :id => 'Another_page' | 343 delete :destroy, :project_id => 1, :id => 'Another_page' |
301 end | 344 end |
302 assert_response :success | 345 assert_response :success |
303 assert_template 'destroy' | 346 assert_template 'destroy' |
304 end | 347 end |
305 | 348 |
306 def test_destroy_parent_with_nullify | 349 def test_destroy_parent_with_nullify |
307 @request.session[:user_id] = 2 | 350 @request.session[:user_id] = 2 |
308 assert_difference('WikiPage.count', -1) do | 351 assert_difference('WikiPage.count', -1) do |
309 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'nullify' | 352 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'nullify' |
310 end | 353 end |
311 assert_redirected_to :action => 'index', :project_id => 'ecookbook' | 354 assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
312 assert_nil WikiPage.find_by_id(2) | 355 assert_nil WikiPage.find_by_id(2) |
313 end | 356 end |
314 | 357 |
315 def test_destroy_parent_with_cascade | 358 def test_destroy_parent_with_cascade |
316 @request.session[:user_id] = 2 | 359 @request.session[:user_id] = 2 |
317 assert_difference('WikiPage.count', -3) do | 360 assert_difference('WikiPage.count', -3) do |
318 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'destroy' | 361 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'destroy' |
319 end | 362 end |
320 assert_redirected_to :action => 'index', :project_id => 'ecookbook' | 363 assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
321 assert_nil WikiPage.find_by_id(2) | 364 assert_nil WikiPage.find_by_id(2) |
322 assert_nil WikiPage.find_by_id(5) | 365 assert_nil WikiPage.find_by_id(5) |
323 end | 366 end |
324 | 367 |
325 def test_destroy_parent_with_reassign | 368 def test_destroy_parent_with_reassign |
326 @request.session[:user_id] = 2 | 369 @request.session[:user_id] = 2 |
327 assert_difference('WikiPage.count', -1) do | 370 assert_difference('WikiPage.count', -1) do |
328 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'reassign', :reassign_to_id => 1 | 371 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'reassign', :reassign_to_id => 1 |
329 end | 372 end |
330 assert_redirected_to :action => 'index', :project_id => 'ecookbook' | 373 assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
331 assert_nil WikiPage.find_by_id(2) | 374 assert_nil WikiPage.find_by_id(2) |
332 assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent | 375 assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent |
333 end | 376 end |
334 | 377 |
335 def test_index | 378 def test_index |
336 get :index, :project_id => 'ecookbook' | 379 get :index, :project_id => 'ecookbook' |
337 assert_response :success | 380 assert_response :success |
338 assert_template 'index' | 381 assert_template 'index' |
339 pages = assigns(:pages) | 382 pages = assigns(:pages) |
340 assert_not_nil pages | 383 assert_not_nil pages |
341 assert_equal Project.find(1).wiki.pages.size, pages.size | 384 assert_equal Project.find(1).wiki.pages.size, pages.size |
342 | 385 assert_equal pages.first.content.updated_on, pages.first.updated_on |
386 | |
343 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' }, | 387 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' }, |
344 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/CookBook_documentation' }, | 388 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/CookBook_documentation' }, |
345 :content => 'CookBook documentation' }, | 389 :content => 'CookBook documentation' }, |
346 :child => { :tag => 'ul', | 390 :child => { :tag => 'ul', |
347 :child => { :tag => 'li', | 391 :child => { :tag => 'li', |
349 :content => 'Page with an inline image' } } } }, | 393 :content => 'Page with an inline image' } } } }, |
350 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Another_page' }, | 394 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Another_page' }, |
351 :content => 'Another page' } } | 395 :content => 'Another page' } } |
352 end | 396 end |
353 | 397 |
398 def test_index_should_include_atom_link | |
399 get :index, :project_id => 'ecookbook' | |
400 assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'} | |
401 end | |
402 | |
354 context "GET :export" do | 403 context "GET :export" do |
355 context "with an authorized user to export the wiki" do | 404 context "with an authorized user to export the wiki" do |
356 setup do | 405 setup do |
357 @request.session[:user_id] = 2 | 406 @request.session[:user_id] = 2 |
358 get :export, :project_id => 'ecookbook' | 407 get :export, :project_id => 'ecookbook' |
359 end | 408 end |
360 | 409 |
361 should_respond_with :success | 410 should_respond_with :success |
362 should_assign_to :pages | 411 should_assign_to :pages |
363 should_respond_with_content_type "text/html" | 412 should_respond_with_content_type "text/html" |
364 should "export all of the wiki pages to a single html file" do | 413 should "export all of the wiki pages to a single html file" do |
365 assert_select "a[name=?]", "CookBook_documentation" | 414 assert_select "a[name=?]", "CookBook_documentation" |
366 assert_select "a[name=?]", "Another_page" | 415 assert_select "a[name=?]", "Another_page" |
367 assert_select "a[name=?]", "Page_with_an_inline_image" | 416 assert_select "a[name=?]", "Page_with_an_inline_image" |
368 end | 417 end |
369 | 418 |
370 end | 419 end |
371 | 420 |
372 context "with an unauthorized user" do | 421 context "with an unauthorized user" do |
373 setup do | 422 setup do |
374 get :export, :project_id => 'ecookbook' | 423 get :export, :project_id => 'ecookbook' |
386 | 435 |
387 should_respond_with :success | 436 should_respond_with :success |
388 should_assign_to :pages | 437 should_assign_to :pages |
389 should_assign_to :pages_by_date | 438 should_assign_to :pages_by_date |
390 should_render_template 'wiki/date_index' | 439 should_render_template 'wiki/date_index' |
391 | 440 |
392 end | 441 should "include atom link" do |
393 | 442 assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'} |
443 end | |
444 end | |
445 | |
394 def test_not_found | 446 def test_not_found |
395 get :show, :project_id => 999 | 447 get :show, :project_id => 999 |
396 assert_response 404 | 448 assert_response 404 |
397 end | 449 end |
398 | 450 |
399 def test_protect_page | 451 def test_protect_page |
400 page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page') | 452 page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page') |
401 assert !page.protected? | 453 assert !page.protected? |
402 @request.session[:user_id] = 2 | 454 @request.session[:user_id] = 2 |
403 post :protect, :project_id => 1, :id => page.title, :protected => '1' | 455 post :protect, :project_id => 1, :id => page.title, :protected => '1' |
404 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page' | 456 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page' |
405 assert page.reload.protected? | 457 assert page.reload.protected? |
406 end | 458 end |
407 | 459 |
408 def test_unprotect_page | 460 def test_unprotect_page |
409 page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation') | 461 page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation') |
410 assert page.protected? | 462 assert page.protected? |
411 @request.session[:user_id] = 2 | 463 @request.session[:user_id] = 2 |
412 post :protect, :project_id => 1, :id => page.title, :protected => '0' | 464 post :protect, :project_id => 1, :id => page.title, :protected => '0' |
413 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'CookBook_documentation' | 465 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'CookBook_documentation' |
414 assert !page.reload.protected? | 466 assert !page.reload.protected? |
415 end | 467 end |
416 | 468 |
417 def test_show_page_with_edit_link | 469 def test_show_page_with_edit_link |
418 @request.session[:user_id] = 2 | 470 @request.session[:user_id] = 2 |
419 get :show, :project_id => 1 | 471 get :show, :project_id => 1 |
420 assert_response :success | 472 assert_response :success |
421 assert_template 'show' | 473 assert_template 'show' |
422 assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' } | 474 assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' } |
423 end | 475 end |
424 | 476 |
425 def test_show_page_without_edit_link | 477 def test_show_page_without_edit_link |
426 @request.session[:user_id] = 4 | 478 @request.session[:user_id] = 4 |
427 get :show, :project_id => 1 | 479 get :show, :project_id => 1 |
428 assert_response :success | 480 assert_response :success |
429 assert_template 'show' | 481 assert_template 'show' |
430 assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' } | 482 assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' } |
431 end | 483 end |
432 | 484 |
433 def test_edit_unprotected_page | 485 def test_edit_unprotected_page |
434 # Non members can edit unprotected wiki pages | 486 # Non members can edit unprotected wiki pages |
435 @request.session[:user_id] = 4 | 487 @request.session[:user_id] = 4 |
436 get :edit, :project_id => 1, :id => 'Another_page' | 488 get :edit, :project_id => 1, :id => 'Another_page' |
437 assert_response :success | 489 assert_response :success |
438 assert_template 'edit' | 490 assert_template 'edit' |
439 end | 491 end |
440 | 492 |
441 def test_edit_protected_page_by_nonmember | 493 def test_edit_protected_page_by_nonmember |
442 # Non members can't edit protected wiki pages | 494 # Non members can't edit protected wiki pages |
443 @request.session[:user_id] = 4 | 495 @request.session[:user_id] = 4 |
444 get :edit, :project_id => 1, :id => 'CookBook_documentation' | 496 get :edit, :project_id => 1, :id => 'CookBook_documentation' |
445 assert_response 403 | 497 assert_response 403 |
446 end | 498 end |
447 | 499 |
448 def test_edit_protected_page_by_member | 500 def test_edit_protected_page_by_member |
449 @request.session[:user_id] = 2 | 501 @request.session[:user_id] = 2 |
450 get :edit, :project_id => 1, :id => 'CookBook_documentation' | 502 get :edit, :project_id => 1, :id => 'CookBook_documentation' |
451 assert_response :success | 503 assert_response :success |
452 assert_template 'edit' | 504 assert_template 'edit' |
453 end | 505 end |
454 | 506 |
455 def test_history_of_non_existing_page_should_return_404 | 507 def test_history_of_non_existing_page_should_return_404 |
456 get :history, :project_id => 1, :id => 'Unknown_page' | 508 get :history, :project_id => 1, :id => 'Unknown_page' |
457 assert_response 404 | 509 assert_response 404 |
458 end | 510 end |
459 end | 511 end |