annotate test/functional/wiki_controller_test.rb @ 1295:622f24f53b42 redmine-2.3

Update to Redmine SVN revision 11972 on 2.3-stable branch
author Chris Cannam
date Fri, 14 Jun 2013 09:02:21 +0100
parents 3e4c3460b6ca
children
rev   line source
Chris@441 1 # Redmine - project management software
Chris@1295 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@441 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@441 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@119 18 require File.expand_path('../../test_helper', __FILE__)
Chris@0 19
Chris@0 20 class WikiControllerTest < ActionController::TestCase
Chris@909 21 fixtures :projects, :users, :roles, :members, :member_roles,
Chris@909 22 :enabled_modules, :wikis, :wiki_pages, :wiki_contents,
Chris@909 23 :wiki_content_versions, :attachments
Chris@441 24
Chris@0 25 def setup
Chris@0 26 User.current = nil
Chris@0 27 end
Chris@441 28
Chris@0 29 def test_show_start_page
chris@37 30 get :show, :project_id => 'ecookbook'
Chris@0 31 assert_response :success
Chris@0 32 assert_template 'show'
Chris@0 33 assert_tag :tag => 'h1', :content => /CookBook documentation/
Chris@0 34
Chris@0 35 # child_pages macro
Chris@0 36 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
Chris@0 37 :child => { :tag => 'li',
Chris@0 38 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
Chris@0 39 :content => 'Page with an inline image' } }
Chris@0 40 end
Chris@909 41
Chris@909 42 def test_export_link
Chris@909 43 Role.anonymous.add_permission! :export_wiki_pages
Chris@909 44 get :show, :project_id => 'ecookbook'
Chris@909 45 assert_response :success
Chris@909 46 assert_tag 'a', :attributes => {:href => '/projects/ecookbook/wiki/CookBook_documentation.txt'}
Chris@909 47 end
Chris@441 48
Chris@0 49 def test_show_page_with_name
chris@37 50 get :show, :project_id => 1, :id => 'Another_page'
Chris@0 51 assert_response :success
Chris@0 52 assert_template 'show'
Chris@0 53 assert_tag :tag => 'h1', :content => /Another page/
Chris@0 54 # Included page with an inline image
Chris@0 55 assert_tag :tag => 'p', :content => /This is an inline image/
Chris@1295 56 assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3/logo.gif',
Chris@0 57 :alt => 'This is a logo' }
Chris@0 58 end
Chris@441 59
Chris@1115 60 def test_show_old_version
Chris@1115 61 get :show, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '2'
Chris@1115 62 assert_response :success
Chris@1115 63 assert_template 'show'
Chris@1115 64
Chris@1115 65 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/1', :text => /Previous/
Chris@1115 66 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2/diff', :text => /diff/
Chris@1115 67 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/3', :text => /Next/
Chris@1115 68 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation', :text => /Current version/
Chris@1115 69 end
Chris@1115 70
Chris@1294 71 def test_show_old_version_with_attachments
Chris@1294 72 page = WikiPage.find(4)
Chris@1294 73 assert page.attachments.any?
Chris@1294 74 content = page.content
Chris@1294 75 content.text = "update"
Chris@1294 76 content.save!
Chris@1294 77
Chris@1294 78 get :show, :project_id => 'ecookbook', :id => page.title, :version => '1'
Chris@1294 79 assert_kind_of WikiContent::Version, assigns(:content)
Chris@1294 80 assert_response :success
Chris@1294 81 assert_template 'show'
Chris@1294 82 end
Chris@1294 83
Chris@1115 84 def test_show_old_version_without_permission_should_be_denied
Chris@1115 85 Role.anonymous.remove_permission! :view_wiki_edits
Chris@1115 86
Chris@1115 87 get :show, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '2'
Chris@1115 88 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fprojects%2Fecookbook%2Fwiki%2FCookBook_documentation%2F2'
Chris@1115 89 end
Chris@1115 90
Chris@1115 91 def test_show_first_version
Chris@1115 92 get :show, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '1'
Chris@1115 93 assert_response :success
Chris@1115 94 assert_template 'show'
Chris@1115 95
Chris@1115 96 assert_select 'a', :text => /Previous/, :count => 0
Chris@1115 97 assert_select 'a', :text => /diff/, :count => 0
Chris@1115 98 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2', :text => /Next/
Chris@1115 99 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation', :text => /Current version/
Chris@1115 100 end
Chris@1115 101
Chris@441 102 def test_show_redirected_page
Chris@441 103 WikiRedirect.create!(:wiki_id => 1, :title => 'Old_title', :redirects_to => 'Another_page')
Chris@441 104
Chris@441 105 get :show, :project_id => 'ecookbook', :id => 'Old_title'
Chris@441 106 assert_redirected_to '/projects/ecookbook/wiki/Another_page'
Chris@441 107 end
Chris@441 108
Chris@0 109 def test_show_with_sidebar
Chris@0 110 page = Project.find(1).wiki.pages.new(:title => 'Sidebar')
Chris@0 111 page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
Chris@0 112 page.save!
Chris@441 113
chris@37 114 get :show, :project_id => 1, :id => 'Another_page'
Chris@0 115 assert_response :success
Chris@0 116 assert_tag :tag => 'div', :attributes => {:id => 'sidebar'},
Chris@0 117 :content => /Side bar content for test_show_with_sidebar/
Chris@0 118 end
Chris@909 119
Chris@909 120 def test_show_should_display_section_edit_links
Chris@909 121 @request.session[:user_id] = 2
Chris@909 122 get :show, :project_id => 1, :id => 'Page with sections'
Chris@909 123 assert_no_tag 'a', :attributes => {
Chris@909 124 :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=1'
Chris@909 125 }
Chris@909 126 assert_tag 'a', :attributes => {
Chris@909 127 :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=2'
Chris@909 128 }
Chris@909 129 assert_tag 'a', :attributes => {
Chris@909 130 :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=3'
Chris@909 131 }
Chris@909 132 end
Chris@909 133
Chris@909 134 def test_show_current_version_should_display_section_edit_links
Chris@909 135 @request.session[:user_id] = 2
Chris@909 136 get :show, :project_id => 1, :id => 'Page with sections', :version => 3
Chris@909 137
Chris@909 138 assert_tag 'a', :attributes => {
Chris@909 139 :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=2'
Chris@909 140 }
Chris@909 141 end
Chris@909 142
Chris@909 143 def test_show_old_version_should_not_display_section_edit_links
Chris@909 144 @request.session[:user_id] = 2
Chris@909 145 get :show, :project_id => 1, :id => 'Page with sections', :version => 2
Chris@909 146
Chris@909 147 assert_no_tag 'a', :attributes => {
Chris@909 148 :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=2'
Chris@909 149 }
Chris@909 150 end
Chris@441 151
Chris@1115 152 def test_show_unexistent_page_without_edit_right
Chris@1115 153 get :show, :project_id => 1, :id => 'Unexistent page'
Chris@1115 154 assert_response 404
Chris@1115 155 end
Chris@1115 156
Chris@0 157 def test_show_unexistent_page_with_edit_right
Chris@0 158 @request.session[:user_id] = 2
chris@37 159 get :show, :project_id => 1, :id => 'Unexistent page'
Chris@0 160 assert_response :success
Chris@0 161 assert_template 'edit'
Chris@0 162 end
Chris@441 163
Chris@1115 164 def test_show_unexistent_page_with_parent_should_preselect_parent
Chris@1115 165 @request.session[:user_id] = 2
Chris@1115 166 get :show, :project_id => 1, :id => 'Unexistent page', :parent => 'Another_page'
Chris@1115 167 assert_response :success
Chris@1115 168 assert_template 'edit'
Chris@1115 169 assert_tag 'select', :attributes => {:name => 'wiki_page[parent_id]'},
Chris@1115 170 :child => {:tag => 'option', :attributes => {:value => '2', :selected => 'selected'}}
Chris@1115 171 end
Chris@1115 172
Chris@1115 173 def test_show_should_not_show_history_without_permission
Chris@1115 174 Role.anonymous.remove_permission! :view_wiki_edits
Chris@1115 175 get :show, :project_id => 1, :id => 'Page with sections', :version => 2
Chris@1115 176
Chris@1115 177 assert_response 302
Chris@1115 178 end
Chris@1115 179
Chris@0 180 def test_create_page
Chris@0 181 @request.session[:user_id] = 2
Chris@1115 182 assert_difference 'WikiPage.count' do
Chris@1115 183 assert_difference 'WikiContent.count' do
Chris@1115 184 put :update, :project_id => 1,
Chris@1115 185 :id => 'New page',
Chris@1115 186 :content => {:comments => 'Created the page',
Chris@1115 187 :text => "h1. New page\n\nThis is a new page",
Chris@1115 188 :version => 0}
Chris@1115 189 end
Chris@1115 190 end
chris@37 191 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'New_page'
Chris@0 192 page = Project.find(1).wiki.find_page('New page')
Chris@0 193 assert !page.new_record?
Chris@0 194 assert_not_nil page.content
Chris@1115 195 assert_nil page.parent
Chris@0 196 assert_equal 'Created the page', page.content.comments
Chris@0 197 end
Chris@441 198
Chris@0 199 def test_create_page_with_attachments
Chris@0 200 @request.session[:user_id] = 2
Chris@0 201 assert_difference 'WikiPage.count' do
Chris@0 202 assert_difference 'Attachment.count' do
chris@37 203 put :update, :project_id => 1,
chris@37 204 :id => 'New page',
Chris@0 205 :content => {:comments => 'Created the page',
Chris@0 206 :text => "h1. New page\n\nThis is a new page",
Chris@0 207 :version => 0},
Chris@0 208 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
Chris@0 209 end
Chris@0 210 end
Chris@0 211 page = Project.find(1).wiki.find_page('New page')
Chris@0 212 assert_equal 1, page.attachments.count
Chris@0 213 assert_equal 'testfile.txt', page.attachments.first.filename
Chris@0 214 end
Chris@119 215
Chris@1115 216 def test_create_page_with_parent
Chris@1115 217 @request.session[:user_id] = 2
Chris@1115 218 assert_difference 'WikiPage.count' do
Chris@1115 219 put :update, :project_id => 1, :id => 'New page',
Chris@1115 220 :content => {:text => "h1. New page\n\nThis is a new page", :version => 0},
Chris@1115 221 :wiki_page => {:parent_id => 2}
Chris@1115 222 end
Chris@1115 223 page = Project.find(1).wiki.find_page('New page')
Chris@1115 224 assert_equal WikiPage.find(2), page.parent
Chris@1115 225 end
Chris@1115 226
Chris@909 227 def test_edit_page
Chris@909 228 @request.session[:user_id] = 2
Chris@909 229 get :edit, :project_id => 'ecookbook', :id => 'Another_page'
Chris@909 230
Chris@909 231 assert_response :success
Chris@909 232 assert_template 'edit'
Chris@909 233
Chris@909 234 assert_tag 'textarea',
Chris@909 235 :attributes => { :name => 'content[text]' },
Chris@1115 236 :content => "\n"+WikiPage.find_by_title('Another_page').content.text
Chris@909 237 end
Chris@909 238
Chris@909 239 def test_edit_section
Chris@909 240 @request.session[:user_id] = 2
Chris@909 241 get :edit, :project_id => 'ecookbook', :id => 'Page_with_sections', :section => 2
Chris@909 242
Chris@909 243 assert_response :success
Chris@909 244 assert_template 'edit'
Chris@909 245
Chris@909 246 page = WikiPage.find_by_title('Page_with_sections')
Chris@909 247 section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
Chris@909 248
Chris@909 249 assert_tag 'textarea',
Chris@909 250 :attributes => { :name => 'content[text]' },
Chris@1115 251 :content => "\n"+section
Chris@909 252 assert_tag 'input',
Chris@909 253 :attributes => { :name => 'section', :type => 'hidden', :value => '2' }
Chris@909 254 assert_tag 'input',
Chris@909 255 :attributes => { :name => 'section_hash', :type => 'hidden', :value => hash }
Chris@909 256 end
Chris@909 257
Chris@909 258 def test_edit_invalid_section_should_respond_with_404
Chris@909 259 @request.session[:user_id] = 2
Chris@909 260 get :edit, :project_id => 'ecookbook', :id => 'Page_with_sections', :section => 10
Chris@909 261
Chris@909 262 assert_response 404
Chris@909 263 end
Chris@909 264
Chris@119 265 def test_update_page
Chris@119 266 @request.session[:user_id] = 2
Chris@119 267 assert_no_difference 'WikiPage.count' do
Chris@119 268 assert_no_difference 'WikiContent.count' do
Chris@119 269 assert_difference 'WikiContent::Version.count' do
Chris@119 270 put :update, :project_id => 1,
Chris@119 271 :id => 'Another_page',
Chris@119 272 :content => {
Chris@119 273 :comments => "my comments",
Chris@119 274 :text => "edited",
Chris@119 275 :version => 1
Chris@119 276 }
Chris@119 277 end
Chris@119 278 end
Chris@119 279 end
Chris@119 280 assert_redirected_to '/projects/ecookbook/wiki/Another_page'
Chris@441 281
Chris@119 282 page = Wiki.find(1).pages.find_by_title('Another_page')
Chris@119 283 assert_equal "edited", page.content.text
Chris@119 284 assert_equal 2, page.content.version
Chris@119 285 assert_equal "my comments", page.content.comments
Chris@119 286 end
Chris@119 287
Chris@1115 288 def test_update_page_with_parent
Chris@1115 289 @request.session[:user_id] = 2
Chris@1115 290 assert_no_difference 'WikiPage.count' do
Chris@1115 291 assert_no_difference 'WikiContent.count' do
Chris@1115 292 assert_difference 'WikiContent::Version.count' do
Chris@1115 293 put :update, :project_id => 1,
Chris@1115 294 :id => 'Another_page',
Chris@1115 295 :content => {
Chris@1115 296 :comments => "my comments",
Chris@1115 297 :text => "edited",
Chris@1115 298 :version => 1
Chris@1115 299 },
Chris@1115 300 :wiki_page => {:parent_id => '1'}
Chris@1115 301 end
Chris@1115 302 end
Chris@1115 303 end
Chris@1115 304 assert_redirected_to '/projects/ecookbook/wiki/Another_page'
Chris@1115 305
Chris@1115 306 page = Wiki.find(1).pages.find_by_title('Another_page')
Chris@1115 307 assert_equal "edited", page.content.text
Chris@1115 308 assert_equal 2, page.content.version
Chris@1115 309 assert_equal "my comments", page.content.comments
Chris@1115 310 assert_equal WikiPage.find(1), page.parent
Chris@1115 311 end
Chris@1115 312
Chris@119 313 def test_update_page_with_failure
Chris@119 314 @request.session[:user_id] = 2
Chris@119 315 assert_no_difference 'WikiPage.count' do
Chris@119 316 assert_no_difference 'WikiContent.count' do
Chris@119 317 assert_no_difference 'WikiContent::Version.count' do
Chris@119 318 put :update, :project_id => 1,
Chris@119 319 :id => 'Another_page',
Chris@119 320 :content => {
Chris@119 321 :comments => 'a' * 300, # failure here, comment is too long
Chris@119 322 :text => 'edited',
Chris@119 323 :version => 1
Chris@119 324 }
Chris@119 325 end
Chris@119 326 end
Chris@119 327 end
Chris@119 328 assert_response :success
Chris@119 329 assert_template 'edit'
Chris@441 330
Chris@119 331 assert_error_tag :descendant => {:content => /Comment is too long/}
Chris@1115 332 assert_tag :tag => 'textarea', :attributes => {:id => 'content_text'}, :content => "\nedited"
Chris@119 333 assert_tag :tag => 'input', :attributes => {:id => 'content_version', :value => '1'}
Chris@119 334 end
Chris@441 335
Chris@1115 336 def test_update_page_with_parent_change_only_should_not_create_content_version
Chris@1115 337 @request.session[:user_id] = 2
Chris@1115 338 assert_no_difference 'WikiPage.count' do
Chris@1115 339 assert_no_difference 'WikiContent.count' do
Chris@1115 340 assert_no_difference 'WikiContent::Version.count' do
Chris@1115 341 put :update, :project_id => 1,
Chris@1115 342 :id => 'Another_page',
Chris@1115 343 :content => {
Chris@1115 344 :comments => '',
Chris@1115 345 :text => Wiki.find(1).find_page('Another_page').content.text,
Chris@1115 346 :version => 1
Chris@1115 347 },
Chris@1115 348 :wiki_page => {:parent_id => '1'}
Chris@1115 349 end
Chris@1115 350 end
Chris@1115 351 end
Chris@1115 352 page = Wiki.find(1).pages.find_by_title('Another_page')
Chris@1115 353 assert_equal 1, page.content.version
Chris@1115 354 assert_equal WikiPage.find(1), page.parent
Chris@1115 355 end
Chris@1115 356
Chris@1115 357 def test_update_page_with_attachments_only_should_not_create_content_version
Chris@1115 358 @request.session[:user_id] = 2
Chris@1115 359 assert_no_difference 'WikiPage.count' do
Chris@1115 360 assert_no_difference 'WikiContent.count' do
Chris@1115 361 assert_no_difference 'WikiContent::Version.count' do
Chris@1115 362 assert_difference 'Attachment.count' do
Chris@1115 363 put :update, :project_id => 1,
Chris@1115 364 :id => 'Another_page',
Chris@1115 365 :content => {
Chris@1115 366 :comments => '',
Chris@1115 367 :text => Wiki.find(1).find_page('Another_page').content.text,
Chris@1115 368 :version => 1
Chris@1115 369 },
Chris@1115 370 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
Chris@1115 371 end
Chris@1115 372 end
Chris@1115 373 end
Chris@1115 374 end
Chris@1115 375 page = Wiki.find(1).pages.find_by_title('Another_page')
Chris@1115 376 assert_equal 1, page.content.version
Chris@1115 377 end
Chris@1115 378
Chris@441 379 def test_update_stale_page_should_not_raise_an_error
Chris@441 380 @request.session[:user_id] = 2
Chris@441 381 c = Wiki.find(1).find_page('Another_page').content
Chris@441 382 c.text = 'Previous text'
Chris@441 383 c.save!
Chris@441 384 assert_equal 2, c.version
Chris@441 385
Chris@441 386 assert_no_difference 'WikiPage.count' do
Chris@441 387 assert_no_difference 'WikiContent.count' do
Chris@441 388 assert_no_difference 'WikiContent::Version.count' do
Chris@441 389 put :update, :project_id => 1,
Chris@441 390 :id => 'Another_page',
Chris@441 391 :content => {
Chris@441 392 :comments => 'My comments',
Chris@441 393 :text => 'Text should not be lost',
Chris@441 394 :version => 1
Chris@441 395 }
Chris@441 396 end
Chris@441 397 end
Chris@441 398 end
Chris@441 399 assert_response :success
Chris@441 400 assert_template 'edit'
Chris@441 401 assert_tag :div,
Chris@441 402 :attributes => { :class => /error/ },
Chris@441 403 :content => /Data has been updated by another user/
Chris@441 404 assert_tag 'textarea',
Chris@441 405 :attributes => { :name => 'content[text]' },
Chris@441 406 :content => /Text should not be lost/
Chris@441 407 assert_tag 'input',
Chris@441 408 :attributes => { :name => 'content[comments]', :value => 'My comments' }
Chris@441 409
Chris@441 410 c.reload
Chris@441 411 assert_equal 'Previous text', c.text
Chris@441 412 assert_equal 2, c.version
Chris@441 413 end
Chris@441 414
Chris@909 415 def test_update_section
Chris@909 416 @request.session[:user_id] = 2
Chris@909 417 page = WikiPage.find_by_title('Page_with_sections')
Chris@909 418 section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
Chris@909 419 text = page.content.text
Chris@909 420
Chris@909 421 assert_no_difference 'WikiPage.count' do
Chris@909 422 assert_no_difference 'WikiContent.count' do
Chris@909 423 assert_difference 'WikiContent::Version.count' do
Chris@909 424 put :update, :project_id => 1, :id => 'Page_with_sections',
Chris@909 425 :content => {
Chris@909 426 :text => "New section content",
Chris@909 427 :version => 3
Chris@909 428 },
Chris@909 429 :section => 2,
Chris@909 430 :section_hash => hash
Chris@909 431 end
Chris@909 432 end
Chris@909 433 end
Chris@909 434 assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections'
Chris@909 435 assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.reload.content.text
Chris@909 436 end
Chris@909 437
Chris@909 438 def test_update_section_should_allow_stale_page_update
Chris@909 439 @request.session[:user_id] = 2
Chris@909 440 page = WikiPage.find_by_title('Page_with_sections')
Chris@909 441 section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
Chris@909 442 text = page.content.text
Chris@909 443
Chris@909 444 assert_no_difference 'WikiPage.count' do
Chris@909 445 assert_no_difference 'WikiContent.count' do
Chris@909 446 assert_difference 'WikiContent::Version.count' do
Chris@909 447 put :update, :project_id => 1, :id => 'Page_with_sections',
Chris@909 448 :content => {
Chris@909 449 :text => "New section content",
Chris@909 450 :version => 2 # Current version is 3
Chris@909 451 },
Chris@909 452 :section => 2,
Chris@909 453 :section_hash => hash
Chris@909 454 end
Chris@909 455 end
Chris@909 456 end
Chris@909 457 assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections'
Chris@909 458 page.reload
Chris@909 459 assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.content.text
Chris@909 460 assert_equal 4, page.content.version
Chris@909 461 end
Chris@909 462
Chris@909 463 def test_update_section_should_not_allow_stale_section_update
Chris@909 464 @request.session[:user_id] = 2
Chris@909 465
Chris@909 466 assert_no_difference 'WikiPage.count' do
Chris@909 467 assert_no_difference 'WikiContent.count' do
Chris@909 468 assert_no_difference 'WikiContent::Version.count' do
Chris@909 469 put :update, :project_id => 1, :id => 'Page_with_sections',
Chris@909 470 :content => {
Chris@909 471 :comments => 'My comments',
Chris@909 472 :text => "Text should not be lost",
Chris@909 473 :version => 3
Chris@909 474 },
Chris@909 475 :section => 2,
Chris@909 476 :section_hash => Digest::MD5.hexdigest("wrong hash")
Chris@909 477 end
Chris@909 478 end
Chris@909 479 end
Chris@909 480 assert_response :success
Chris@909 481 assert_template 'edit'
Chris@909 482 assert_tag :div,
Chris@909 483 :attributes => { :class => /error/ },
Chris@909 484 :content => /Data has been updated by another user/
Chris@909 485 assert_tag 'textarea',
Chris@909 486 :attributes => { :name => 'content[text]' },
Chris@909 487 :content => /Text should not be lost/
Chris@909 488 assert_tag 'input',
Chris@909 489 :attributes => { :name => 'content[comments]', :value => 'My comments' }
Chris@909 490 end
Chris@909 491
Chris@0 492 def test_preview
Chris@0 493 @request.session[:user_id] = 2
chris@37 494 xhr :post, :preview, :project_id => 1, :id => 'CookBook_documentation',
Chris@0 495 :content => { :comments => '',
Chris@0 496 :text => 'this is a *previewed text*',
Chris@0 497 :version => 3 }
Chris@0 498 assert_response :success
Chris@0 499 assert_template 'common/_preview'
Chris@0 500 assert_tag :tag => 'strong', :content => /previewed text/
Chris@0 501 end
Chris@441 502
Chris@0 503 def test_preview_new_page
Chris@0 504 @request.session[:user_id] = 2
chris@37 505 xhr :post, :preview, :project_id => 1, :id => 'New page',
Chris@0 506 :content => { :text => 'h1. New page',
Chris@0 507 :comments => '',
Chris@0 508 :version => 0 }
Chris@0 509 assert_response :success
Chris@0 510 assert_template 'common/_preview'
Chris@0 511 assert_tag :tag => 'h1', :content => /New page/
Chris@0 512 end
Chris@441 513
Chris@0 514 def test_history
Chris@1115 515 @request.session[:user_id] = 2
Chris@1115 516 get :history, :project_id => 'ecookbook', :id => 'CookBook_documentation'
Chris@0 517 assert_response :success
Chris@0 518 assert_template 'history'
Chris@0 519 assert_not_nil assigns(:versions)
Chris@0 520 assert_equal 3, assigns(:versions).size
Chris@1115 521
Chris@0 522 assert_select "input[type=submit][name=commit]"
Chris@1115 523 assert_select 'td' do
Chris@1115 524 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2', :text => '2'
Chris@1115 525 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2/annotate', :text => 'Annotate'
Chris@1115 526 assert_select 'a[href=?]', '/projects/ecookbook/wiki/CookBook_documentation/2', :text => 'Delete'
Chris@1115 527 end
Chris@0 528 end
Chris@0 529
Chris@0 530 def test_history_with_one_version
Chris@1115 531 @request.session[:user_id] = 2
Chris@1115 532 get :history, :project_id => 'ecookbook', :id => 'Another_page'
Chris@0 533 assert_response :success
Chris@0 534 assert_template 'history'
Chris@0 535 assert_not_nil assigns(:versions)
Chris@0 536 assert_equal 1, assigns(:versions).size
Chris@0 537 assert_select "input[type=submit][name=commit]", false
Chris@1115 538 assert_select 'td' do
Chris@1115 539 assert_select 'a[href=?]', '/projects/ecookbook/wiki/Another_page/1', :text => '1'
Chris@1115 540 assert_select 'a[href=?]', '/projects/ecookbook/wiki/Another_page/1/annotate', :text => 'Annotate'
Chris@1115 541 assert_select 'a[href=?]', '/projects/ecookbook/wiki/Another_page/1', :text => 'Delete', :count => 0
Chris@1115 542 end
Chris@0 543 end
Chris@441 544
Chris@0 545 def test_diff
Chris@1115 546 content = WikiPage.find(1).content
Chris@1115 547 assert_difference 'WikiContent::Version.count', 2 do
Chris@1115 548 content.text = "Line removed\nThis is a sample text for testing diffs"
Chris@1115 549 content.save!
Chris@1115 550 content.text = "This is a sample text for testing diffs\nLine added"
Chris@1115 551 content.save!
Chris@1115 552 end
Chris@1115 553
Chris@1115 554 get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => content.version, :version_from => (content.version - 1)
Chris@0 555 assert_response :success
Chris@0 556 assert_template 'diff'
Chris@1115 557 assert_select 'span.diff_out', :text => 'Line removed'
Chris@1115 558 assert_select 'span.diff_in', :text => 'Line added'
Chris@1115 559 end
Chris@1115 560
Chris@1115 561 def test_diff_with_invalid_version_should_respond_with_404
Chris@1115 562 get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => '99'
Chris@1115 563 assert_response 404
Chris@1115 564 end
Chris@1115 565
Chris@1115 566 def test_diff_with_invalid_version_from_should_respond_with_404
Chris@1115 567 get :diff, :project_id => 1, :id => 'CookBook_documentation', :version => '99', :version_from => '98'
Chris@1115 568 assert_response 404
Chris@0 569 end
Chris@441 570
Chris@0 571 def test_annotate
chris@37 572 get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => 2
Chris@0 573 assert_response :success
Chris@0 574 assert_template 'annotate'
Chris@909 575
Chris@0 576 # Line 1
Chris@507 577 assert_tag :tag => 'tr', :child => {
Chris@507 578 :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1', :sibling => {
Chris@507 579 :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/, :sibling => {
Chris@507 580 :tag => 'td', :content => /h1\. CookBook documentation/
Chris@507 581 }
Chris@507 582 }
Chris@507 583 }
Chris@909 584
Chris@507 585 # Line 5
Chris@507 586 assert_tag :tag => 'tr', :child => {
Chris@507 587 :tag => 'th', :attributes => {:class => 'line-num'}, :content => '5', :sibling => {
Chris@1295 588 :tag => 'td', :attributes => {:class => 'author'}, :content => /Redmine Admin/, :sibling => {
Chris@507 589 :tag => 'td', :content => /Some updated \[\[documentation\]\] here/
Chris@507 590 }
Chris@507 591 }
Chris@507 592 }
Chris@0 593 end
chris@37 594
Chris@1115 595 def test_annotate_with_invalid_version_should_respond_with_404
Chris@1115 596 get :annotate, :project_id => 1, :id => 'CookBook_documentation', :version => '99'
Chris@1115 597 assert_response 404
Chris@1115 598 end
Chris@1115 599
chris@37 600 def test_get_rename
chris@37 601 @request.session[:user_id] = 2
chris@37 602 get :rename, :project_id => 1, :id => 'Another_page'
chris@37 603 assert_response :success
chris@37 604 assert_template 'rename'
chris@37 605 assert_tag 'option',
chris@37 606 :attributes => {:value => ''},
chris@37 607 :content => '',
chris@37 608 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
chris@37 609 assert_no_tag 'option',
chris@37 610 :attributes => {:selected => 'selected'},
chris@37 611 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
chris@37 612 end
Chris@441 613
chris@37 614 def test_get_rename_child_page
chris@37 615 @request.session[:user_id] = 2
chris@37 616 get :rename, :project_id => 1, :id => 'Child_1'
chris@37 617 assert_response :success
chris@37 618 assert_template 'rename'
chris@37 619 assert_tag 'option',
chris@37 620 :attributes => {:value => ''},
chris@37 621 :content => '',
chris@37 622 :parent => {:tag => 'select', :attributes => {:name => 'wiki_page[parent_id]'}}
chris@37 623 assert_tag 'option',
chris@37 624 :attributes => {:value => '2', :selected => 'selected'},
chris@37 625 :content => /Another page/,
chris@37 626 :parent => {
chris@37 627 :tag => 'select',
chris@37 628 :attributes => {:name => 'wiki_page[parent_id]'}
chris@37 629 }
chris@37 630 end
Chris@441 631
Chris@0 632 def test_rename_with_redirect
Chris@0 633 @request.session[:user_id] = 2
chris@37 634 post :rename, :project_id => 1, :id => 'Another_page',
Chris@0 635 :wiki_page => { :title => 'Another renamed page',
Chris@0 636 :redirect_existing_links => 1 }
chris@37 637 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
Chris@0 638 wiki = Project.find(1).wiki
Chris@0 639 # Check redirects
Chris@0 640 assert_not_nil wiki.find_page('Another page')
Chris@0 641 assert_nil wiki.find_page('Another page', :with_redirect => false)
Chris@0 642 end
Chris@0 643
Chris@0 644 def test_rename_without_redirect
Chris@0 645 @request.session[:user_id] = 2
chris@37 646 post :rename, :project_id => 1, :id => 'Another_page',
Chris@0 647 :wiki_page => { :title => 'Another renamed page',
Chris@0 648 :redirect_existing_links => "0" }
chris@37 649 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page'
Chris@0 650 wiki = Project.find(1).wiki
Chris@0 651 # Check that there's no redirects
Chris@0 652 assert_nil wiki.find_page('Another page')
Chris@0 653 end
Chris@441 654
chris@37 655 def test_rename_with_parent_assignment
chris@37 656 @request.session[:user_id] = 2
chris@37 657 post :rename, :project_id => 1, :id => 'Another_page',
chris@37 658 :wiki_page => { :title => 'Another page', :redirect_existing_links => "0", :parent_id => '4' }
chris@37 659 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
chris@37 660 assert_equal WikiPage.find(4), WikiPage.find_by_title('Another_page').parent
chris@37 661 end
chris@37 662
chris@37 663 def test_rename_with_parent_unassignment
chris@37 664 @request.session[:user_id] = 2
chris@37 665 post :rename, :project_id => 1, :id => 'Child_1',
chris@37 666 :wiki_page => { :title => 'Child 1', :redirect_existing_links => "0", :parent_id => '' }
chris@37 667 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Child_1'
chris@37 668 assert_nil WikiPage.find_by_title('Child_1').parent
chris@37 669 end
Chris@441 670
Chris@1115 671 def test_destroy_a_page_without_children_should_not_ask_confirmation
Chris@0 672 @request.session[:user_id] = 2
Chris@1115 673 delete :destroy, :project_id => 1, :id => 'Child_2'
chris@37 674 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
Chris@0 675 end
Chris@441 676
Chris@1115 677 def test_destroy_parent_should_ask_confirmation
Chris@0 678 @request.session[:user_id] = 2
Chris@0 679 assert_no_difference('WikiPage.count') do
chris@37 680 delete :destroy, :project_id => 1, :id => 'Another_page'
Chris@0 681 end
Chris@0 682 assert_response :success
Chris@0 683 assert_template 'destroy'
Chris@1115 684 assert_select 'form' do
Chris@1115 685 assert_select 'input[name=todo][value=nullify]'
Chris@1115 686 assert_select 'input[name=todo][value=destroy]'
Chris@1115 687 assert_select 'input[name=todo][value=reassign]'
Chris@1115 688 end
Chris@0 689 end
Chris@441 690
Chris@1115 691 def test_destroy_parent_with_nullify_should_delete_parent_only
Chris@0 692 @request.session[:user_id] = 2
Chris@0 693 assert_difference('WikiPage.count', -1) do
chris@37 694 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'nullify'
Chris@0 695 end
chris@37 696 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
Chris@0 697 assert_nil WikiPage.find_by_id(2)
Chris@0 698 end
Chris@441 699
Chris@1115 700 def test_destroy_parent_with_cascade_should_delete_descendants
Chris@0 701 @request.session[:user_id] = 2
Chris@1115 702 assert_difference('WikiPage.count', -4) do
chris@37 703 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'destroy'
Chris@0 704 end
chris@37 705 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
Chris@0 706 assert_nil WikiPage.find_by_id(2)
Chris@0 707 assert_nil WikiPage.find_by_id(5)
Chris@0 708 end
Chris@441 709
Chris@0 710 def test_destroy_parent_with_reassign
Chris@0 711 @request.session[:user_id] = 2
Chris@0 712 assert_difference('WikiPage.count', -1) do
chris@37 713 delete :destroy, :project_id => 1, :id => 'Another_page', :todo => 'reassign', :reassign_to_id => 1
Chris@0 714 end
chris@37 715 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
Chris@0 716 assert_nil WikiPage.find_by_id(2)
Chris@0 717 assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent
Chris@0 718 end
Chris@441 719
Chris@1115 720 def test_destroy_version
Chris@1115 721 @request.session[:user_id] = 2
Chris@1115 722 assert_difference 'WikiContent::Version.count', -1 do
Chris@1115 723 assert_no_difference 'WikiContent.count' do
Chris@1115 724 assert_no_difference 'WikiPage.count' do
Chris@1115 725 delete :destroy_version, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => 2
Chris@1115 726 assert_redirected_to '/projects/ecookbook/wiki/CookBook_documentation/history'
Chris@1115 727 end
Chris@1115 728 end
Chris@1115 729 end
Chris@1115 730 end
Chris@1115 731
chris@37 732 def test_index
chris@37 733 get :index, :project_id => 'ecookbook'
Chris@0 734 assert_response :success
chris@37 735 assert_template 'index'
Chris@0 736 pages = assigns(:pages)
Chris@0 737 assert_not_nil pages
Chris@0 738 assert_equal Project.find(1).wiki.pages.size, pages.size
Chris@441 739 assert_equal pages.first.content.updated_on, pages.first.updated_on
Chris@441 740
Chris@0 741 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
Chris@0 742 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/CookBook_documentation' },
Chris@0 743 :content => 'CookBook documentation' },
Chris@0 744 :child => { :tag => 'ul',
Chris@0 745 :child => { :tag => 'li',
Chris@0 746 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
Chris@0 747 :content => 'Page with an inline image' } } } },
Chris@0 748 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Another_page' },
Chris@0 749 :content => 'Another page' } }
Chris@0 750 end
chris@37 751
Chris@441 752 def test_index_should_include_atom_link
Chris@441 753 get :index, :project_id => 'ecookbook'
Chris@441 754 assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'}
Chris@441 755 end
Chris@441 756
Chris@1115 757 def test_export_to_html
Chris@1115 758 @request.session[:user_id] = 2
Chris@1115 759 get :export, :project_id => 'ecookbook'
Chris@441 760
Chris@1115 761 assert_response :success
Chris@1115 762 assert_not_nil assigns(:pages)
Chris@1115 763 assert assigns(:pages).any?
Chris@1115 764 assert_equal "text/html", @response.content_type
Chris@441 765
Chris@1115 766 assert_select "a[name=?]", "CookBook_documentation"
Chris@1115 767 assert_select "a[name=?]", "Another_page"
Chris@1115 768 assert_select "a[name=?]", "Page_with_an_inline_image"
chris@37 769 end
chris@37 770
Chris@1115 771 def test_export_to_pdf
Chris@1115 772 @request.session[:user_id] = 2
Chris@1115 773 get :export, :project_id => 'ecookbook', :format => 'pdf'
chris@37 774
Chris@1115 775 assert_response :success
Chris@1115 776 assert_not_nil assigns(:pages)
Chris@1115 777 assert assigns(:pages).any?
Chris@1115 778 assert_equal 'application/pdf', @response.content_type
Chris@1115 779 assert_equal 'attachment; filename="ecookbook.pdf"', @response.headers['Content-Disposition']
Chris@1115 780 assert @response.body.starts_with?('%PDF')
Chris@1115 781 end
Chris@441 782
Chris@1115 783 def test_export_without_permission_should_be_denied
Chris@1115 784 @request.session[:user_id] = 2
Chris@1115 785 Role.find_by_name('Manager').remove_permission! :export_wiki_pages
Chris@1115 786 get :export, :project_id => 'ecookbook'
Chris@1115 787
Chris@1115 788 assert_response 403
Chris@1115 789 end
Chris@1115 790
Chris@1115 791 def test_date_index
Chris@1115 792 get :date_index, :project_id => 'ecookbook'
Chris@1115 793
Chris@1115 794 assert_response :success
Chris@1115 795 assert_template 'date_index'
Chris@1115 796 assert_not_nil assigns(:pages)
Chris@1115 797 assert_not_nil assigns(:pages_by_date)
Chris@1115 798
Chris@1115 799 assert_tag 'a', :attributes => { :href => '/projects/ecookbook/activity.atom?show_wiki_edits=1'}
chris@37 800 end
Chris@441 801
Chris@0 802 def test_not_found
chris@37 803 get :show, :project_id => 999
Chris@0 804 assert_response 404
Chris@0 805 end
Chris@441 806
Chris@0 807 def test_protect_page
Chris@0 808 page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page')
Chris@0 809 assert !page.protected?
Chris@0 810 @request.session[:user_id] = 2
chris@37 811 post :protect, :project_id => 1, :id => page.title, :protected => '1'
chris@37 812 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page'
Chris@0 813 assert page.reload.protected?
Chris@0 814 end
Chris@441 815
Chris@0 816 def test_unprotect_page
Chris@0 817 page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation')
Chris@0 818 assert page.protected?
Chris@0 819 @request.session[:user_id] = 2
chris@37 820 post :protect, :project_id => 1, :id => page.title, :protected => '0'
chris@37 821 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'CookBook_documentation'
Chris@0 822 assert !page.reload.protected?
Chris@0 823 end
Chris@441 824
Chris@0 825 def test_show_page_with_edit_link
Chris@0 826 @request.session[:user_id] = 2
chris@37 827 get :show, :project_id => 1
Chris@0 828 assert_response :success
Chris@0 829 assert_template 'show'
Chris@0 830 assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
Chris@0 831 end
Chris@441 832
Chris@0 833 def test_show_page_without_edit_link
Chris@0 834 @request.session[:user_id] = 4
chris@37 835 get :show, :project_id => 1
Chris@0 836 assert_response :success
Chris@0 837 assert_template 'show'
Chris@0 838 assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
Chris@441 839 end
Chris@441 840
Chris@909 841 def test_show_pdf
Chris@909 842 @request.session[:user_id] = 2
Chris@909 843 get :show, :project_id => 1, :format => 'pdf'
Chris@909 844 assert_response :success
Chris@909 845 assert_not_nil assigns(:page)
Chris@909 846 assert_equal 'application/pdf', @response.content_type
Chris@909 847 assert_equal 'attachment; filename="CookBook_documentation.pdf"',
Chris@909 848 @response.headers['Content-Disposition']
Chris@909 849 end
Chris@909 850
Chris@909 851 def test_show_html
Chris@909 852 @request.session[:user_id] = 2
Chris@909 853 get :show, :project_id => 1, :format => 'html'
Chris@909 854 assert_response :success
Chris@909 855 assert_not_nil assigns(:page)
Chris@909 856 assert_equal 'text/html', @response.content_type
Chris@909 857 assert_equal 'attachment; filename="CookBook_documentation.html"',
Chris@909 858 @response.headers['Content-Disposition']
Chris@1115 859 assert_tag 'h1', :content => 'CookBook documentation'
Chris@1115 860 end
Chris@1115 861
Chris@1115 862 def test_show_versioned_html
Chris@1115 863 @request.session[:user_id] = 2
Chris@1115 864 get :show, :project_id => 1, :format => 'html', :version => 2
Chris@1115 865 assert_response :success
Chris@1115 866 assert_not_nil assigns(:content)
Chris@1115 867 assert_equal 2, assigns(:content).version
Chris@1115 868 assert_equal 'text/html', @response.content_type
Chris@1115 869 assert_equal 'attachment; filename="CookBook_documentation.html"',
Chris@1115 870 @response.headers['Content-Disposition']
Chris@1115 871 assert_tag 'h1', :content => 'CookBook documentation'
Chris@909 872 end
Chris@909 873
Chris@909 874 def test_show_txt
Chris@909 875 @request.session[:user_id] = 2
Chris@909 876 get :show, :project_id => 1, :format => 'txt'
Chris@909 877 assert_response :success
Chris@909 878 assert_not_nil assigns(:page)
Chris@909 879 assert_equal 'text/plain', @response.content_type
Chris@909 880 assert_equal 'attachment; filename="CookBook_documentation.txt"',
Chris@909 881 @response.headers['Content-Disposition']
Chris@1115 882 assert_include 'h1. CookBook documentation', @response.body
Chris@1115 883 end
Chris@1115 884
Chris@1115 885 def test_show_versioned_txt
Chris@1115 886 @request.session[:user_id] = 2
Chris@1115 887 get :show, :project_id => 1, :format => 'txt', :version => 2
Chris@1115 888 assert_response :success
Chris@1115 889 assert_not_nil assigns(:content)
Chris@1115 890 assert_equal 2, assigns(:content).version
Chris@1115 891 assert_equal 'text/plain', @response.content_type
Chris@1115 892 assert_equal 'attachment; filename="CookBook_documentation.txt"',
Chris@1115 893 @response.headers['Content-Disposition']
Chris@1115 894 assert_include 'h1. CookBook documentation', @response.body
Chris@909 895 end
Chris@909 896
Chris@0 897 def test_edit_unprotected_page
Chris@0 898 # Non members can edit unprotected wiki pages
Chris@0 899 @request.session[:user_id] = 4
chris@37 900 get :edit, :project_id => 1, :id => 'Another_page'
Chris@0 901 assert_response :success
Chris@0 902 assert_template 'edit'
Chris@0 903 end
Chris@441 904
Chris@0 905 def test_edit_protected_page_by_nonmember
Chris@0 906 # Non members can't edit protected wiki pages
Chris@0 907 @request.session[:user_id] = 4
chris@37 908 get :edit, :project_id => 1, :id => 'CookBook_documentation'
Chris@0 909 assert_response 403
Chris@0 910 end
Chris@441 911
Chris@0 912 def test_edit_protected_page_by_member
Chris@0 913 @request.session[:user_id] = 2
chris@37 914 get :edit, :project_id => 1, :id => 'CookBook_documentation'
Chris@0 915 assert_response :success
Chris@441 916 assert_template 'edit'
Chris@0 917 end
Chris@441 918
Chris@0 919 def test_history_of_non_existing_page_should_return_404
chris@37 920 get :history, :project_id => 1, :id => 'Unknown_page'
Chris@0 921 assert_response 404
Chris@0 922 end
Chris@1115 923
Chris@1115 924 def test_add_attachment
Chris@1115 925 @request.session[:user_id] = 2
Chris@1115 926 assert_difference 'Attachment.count' do
Chris@1115 927 post :add_attachment, :project_id => 1, :id => 'CookBook_documentation',
Chris@1115 928 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
Chris@1115 929 end
Chris@1115 930 attachment = Attachment.first(:order => 'id DESC')
Chris@1115 931 assert_equal Wiki.find(1).find_page('CookBook_documentation'), attachment.container
Chris@1115 932 end
Chris@0 933 end