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