annotate .svn/pristine/69/694cd2c99623d577c90a26a298a76c97fefa807e.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

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