annotate test/functional/projects_controller_test.rb @ 1628:9c5f8e24dadc live tip

Quieten this cron script
author Chris Cannam
date Tue, 25 Aug 2020 11:38:49 +0100
parents dffacf8a6908
children
rev   line source
Chris@0 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 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 ProjectsControllerTest < ActionController::TestCase
Chris@1517 21 fixtures :projects, :versions, :users, :roles, :members,
Chris@1517 22 :member_roles, :issues, :journals, :journal_details,
Chris@1517 23 :trackers, :projects_trackers, :issue_statuses,
Chris@1517 24 :enabled_modules, :enumerations, :boards, :messages,
Chris@0 25 :attachments, :custom_fields, :custom_values, :time_entries
Chris@0 26
Chris@0 27 def setup
Chris@0 28 @request.session[:user_id] = nil
Chris@0 29 Setting.default_language = 'en'
Chris@0 30 end
Chris@441 31
Chris@1464 32 def test_index_by_anonymous_should_not_show_private_projects
Chris@0 33 get :index
Chris@0 34 assert_response :success
Chris@0 35 assert_template 'index'
Chris@1464 36 projects = assigns(:projects)
Chris@1464 37 assert_not_nil projects
Chris@1464 38 assert projects.all?(&:is_public?)
Chris@441 39
Chris@1464 40 assert_select 'ul' do
Chris@1464 41 assert_select 'li' do
Chris@1464 42 assert_select 'a', :text => 'eCookbook'
Chris@1464 43 assert_select 'ul' do
Chris@1464 44 assert_select 'a', :text => 'Child of private child'
Chris@1464 45 end
Chris@1464 46 end
Chris@1464 47 end
Chris@1464 48 assert_select 'a', :text => /Private child of eCookbook/, :count => 0
Chris@0 49 end
Chris@441 50
Chris@0 51 def test_index_atom
Chris@0 52 get :index, :format => 'atom'
Chris@0 53 assert_response :success
Chris@1115 54 assert_template 'common/feed'
Chris@0 55 assert_select 'feed>title', :text => 'Redmine: Latest projects'
Chris@1464 56 assert_select 'feed>entry', :count => Project.visible(User.current).count
Chris@0 57 end
Chris@441 58
Chris@1464 59 test "#index by non-admin user with view_time_entries permission should show overall spent time link" do
Chris@1464 60 @request.session[:user_id] = 3
Chris@1464 61 get :index
Chris@1464 62 assert_template 'index'
Chris@1464 63 assert_select 'a[href=?]', '/time_entries'
Chris@1464 64 end
Chris@441 65
Chris@1464 66 test "#index by non-admin user without view_time_entries permission should not show overall spent time link" do
Chris@1464 67 Role.find(2).remove_permission! :view_time_entries
Chris@1464 68 Role.non_member.remove_permission! :view_time_entries
Chris@1464 69 Role.anonymous.remove_permission! :view_time_entries
Chris@1464 70 @request.session[:user_id] = 3
Chris@1464 71
Chris@1464 72 get :index
Chris@1464 73 assert_template 'index'
Chris@1464 74 assert_select 'a[href=?]', '/time_entries', 0
Chris@1464 75 end
Chris@1464 76
Chris@1464 77 test "#new by admin user should accept get" do
Chris@1464 78 @request.session[:user_id] = 1
Chris@1464 79
Chris@1464 80 get :new
Chris@1464 81 assert_response :success
Chris@1464 82 assert_template 'new'
Chris@1464 83 end
Chris@1464 84
Chris@1464 85 test "#new by non-admin user with add_project permission should accept get" do
Chris@1464 86 Role.non_member.add_permission! :add_project
Chris@1464 87 @request.session[:user_id] = 9
Chris@1464 88
Chris@1464 89 get :new
Chris@1464 90 assert_response :success
Chris@1464 91 assert_template 'new'
Chris@1464 92 assert_select 'select[name=?]', 'project[parent_id]', 0
Chris@1464 93 end
Chris@1464 94
Chris@1464 95 test "#new by non-admin user with add_subprojects permission should accept get" do
Chris@1464 96 Role.find(1).remove_permission! :add_project
Chris@1464 97 Role.find(1).add_permission! :add_subprojects
Chris@1464 98 @request.session[:user_id] = 2
Chris@1464 99
Chris@1464 100 get :new, :parent_id => 'ecookbook'
Chris@1464 101 assert_response :success
Chris@1464 102 assert_template 'new'
Chris@1464 103
Chris@1464 104 assert_select 'select[name=?]', 'project[parent_id]' do
Chris@1464 105 # parent project selected
Chris@1464 106 assert_select 'option[value=1][selected=selected]'
Chris@1464 107 # no empty value
Chris@1464 108 assert_select 'option[value=]', 0
Chris@441 109 end
Chris@0 110 end
Chris@441 111
Chris@1464 112 test "#create by admin user should create a new project" do
Chris@1464 113 @request.session[:user_id] = 1
Chris@441 114
Chris@1464 115 post :create,
Chris@1464 116 :project => {
Chris@1464 117 :name => "blog",
Chris@1464 118 :description => "weblog",
Chris@1464 119 :homepage => 'http://weblog',
Chris@1464 120 :identifier => "blog",
Chris@1464 121 :is_public => 1,
Chris@1464 122 :custom_field_values => { '3' => 'Beta' },
Chris@1464 123 :tracker_ids => ['1', '3'],
Chris@1464 124 # an issue custom field that is not for all project
Chris@1464 125 :issue_custom_field_ids => ['9'],
Chris@1464 126 :enabled_module_names => ['issue_tracking', 'news', 'repository']
Chris@1464 127 }
Chris@1464 128 assert_redirected_to '/projects/blog/settings'
chris@22 129
Chris@1464 130 project = Project.find_by_name('blog')
Chris@1464 131 assert_kind_of Project, project
Chris@1464 132 assert project.active?
Chris@1464 133 assert_equal 'weblog', project.description
Chris@1464 134 assert_equal 'http://weblog', project.homepage
Chris@1464 135 assert_equal true, project.is_public?
Chris@1464 136 assert_nil project.parent
Chris@1464 137 assert_equal 'Beta', project.custom_value_for(3).value
Chris@1464 138 assert_equal [1, 3], project.trackers.map(&:id).sort
Chris@1464 139 assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort
Chris@1464 140 assert project.issue_custom_fields.include?(IssueCustomField.find(9))
Chris@1464 141 end
Chris@1464 142
Chris@1464 143 test "#create by admin user should create a new subproject" do
Chris@1464 144 @request.session[:user_id] = 1
Chris@1464 145
Chris@1464 146 assert_difference 'Project.count' do
Chris@1464 147 post :create, :project => { :name => "blog",
Chris@1464 148 :description => "weblog",
Chris@1464 149 :identifier => "blog",
Chris@1464 150 :is_public => 1,
Chris@1464 151 :custom_field_values => { '3' => 'Beta' },
Chris@1464 152 :parent_id => 1
Chris@1464 153 }
Chris@1464 154 assert_redirected_to '/projects/blog/settings'
chris@22 155 end
chris@22 156
Chris@1464 157 project = Project.find_by_name('blog')
Chris@1464 158 assert_kind_of Project, project
Chris@1464 159 assert_equal Project.find(1), project.parent
Chris@1464 160 end
chris@22 161
Chris@1464 162 test "#create by admin user should continue" do
Chris@1464 163 @request.session[:user_id] = 1
Chris@1464 164
Chris@1464 165 assert_difference 'Project.count' do
Chris@1464 166 post :create, :project => {:name => "blog", :identifier => "blog"}, :continue => 'Create and continue'
Chris@1464 167 end
Chris@1464 168 assert_redirected_to '/projects/new'
Chris@1464 169 end
Chris@1464 170
Chris@1464 171 test "#create by non-admin user with add_project permission should create a new project" do
Chris@1464 172 Role.non_member.add_permission! :add_project
Chris@1464 173 @request.session[:user_id] = 9
Chris@1464 174
Chris@1464 175 post :create, :project => { :name => "blog",
Chris@1464 176 :description => "weblog",
Chris@1464 177 :identifier => "blog",
Chris@1464 178 :is_public => 1,
Chris@1464 179 :custom_field_values => { '3' => 'Beta' },
Chris@1464 180 :tracker_ids => ['1', '3'],
Chris@1464 181 :enabled_module_names => ['issue_tracking', 'news', 'repository']
Chris@1464 182 }
Chris@1464 183
Chris@1464 184 assert_redirected_to '/projects/blog/settings'
Chris@1464 185
Chris@1464 186 project = Project.find_by_name('blog')
Chris@1464 187 assert_kind_of Project, project
Chris@1464 188 assert_equal 'weblog', project.description
Chris@1464 189 assert_equal true, project.is_public?
Chris@1464 190 assert_equal [1, 3], project.trackers.map(&:id).sort
Chris@1464 191 assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort
Chris@1464 192
Chris@1464 193 # User should be added as a project member
Chris@1464 194 assert User.find(9).member_of?(project)
Chris@1464 195 assert_equal 1, project.members.size
Chris@1464 196 end
Chris@1464 197
Chris@1464 198 test "#create by non-admin user with add_project permission should fail with parent_id" do
Chris@1464 199 Role.non_member.add_permission! :add_project
Chris@1464 200 @request.session[:user_id] = 9
Chris@1464 201
Chris@1464 202 assert_no_difference 'Project.count' do
Chris@1464 203 post :create, :project => { :name => "blog",
Chris@1464 204 :description => "weblog",
Chris@1464 205 :identifier => "blog",
Chris@1464 206 :is_public => 1,
Chris@1464 207 :custom_field_values => { '3' => 'Beta' },
Chris@1464 208 :parent_id => 1
Chris@1464 209 }
Chris@1464 210 end
Chris@1464 211 assert_response :success
Chris@1464 212 project = assigns(:project)
Chris@1464 213 assert_kind_of Project, project
Chris@1464 214 assert_not_equal [], project.errors[:parent_id]
Chris@1464 215 end
Chris@1464 216
Chris@1464 217 test "#create by non-admin user with add_subprojects permission should create a project with a parent_id" do
Chris@1464 218 Role.find(1).remove_permission! :add_project
Chris@1464 219 Role.find(1).add_permission! :add_subprojects
Chris@1464 220 @request.session[:user_id] = 2
Chris@1464 221
Chris@1464 222 post :create, :project => { :name => "blog",
Chris@1464 223 :description => "weblog",
Chris@1464 224 :identifier => "blog",
Chris@1464 225 :is_public => 1,
Chris@1464 226 :custom_field_values => { '3' => 'Beta' },
Chris@1464 227 :parent_id => 1
Chris@1464 228 }
Chris@1464 229 assert_redirected_to '/projects/blog/settings'
Chris@1464 230 project = Project.find_by_name('blog')
Chris@1464 231 end
Chris@1464 232
Chris@1464 233 test "#create by non-admin user with add_subprojects permission should fail without parent_id" do
Chris@1464 234 Role.find(1).remove_permission! :add_project
Chris@1464 235 Role.find(1).add_permission! :add_subprojects
Chris@1464 236 @request.session[:user_id] = 2
Chris@1464 237
Chris@1464 238 assert_no_difference 'Project.count' do
Chris@1464 239 post :create, :project => { :name => "blog",
Chris@1464 240 :description => "weblog",
Chris@1464 241 :identifier => "blog",
Chris@1464 242 :is_public => 1,
Chris@1464 243 :custom_field_values => { '3' => 'Beta' }
Chris@1464 244 }
Chris@1464 245 end
Chris@1464 246 assert_response :success
Chris@1464 247 project = assigns(:project)
Chris@1464 248 assert_kind_of Project, project
Chris@1464 249 assert_not_equal [], project.errors[:parent_id]
Chris@1464 250 end
Chris@1464 251
Chris@1464 252 test "#create by non-admin user with add_subprojects permission should fail with unauthorized parent_id" do
Chris@1464 253 Role.find(1).remove_permission! :add_project
Chris@1464 254 Role.find(1).add_permission! :add_subprojects
Chris@1464 255 @request.session[:user_id] = 2
Chris@1464 256
Chris@1464 257 assert !User.find(2).member_of?(Project.find(6))
Chris@1464 258 assert_no_difference 'Project.count' do
Chris@1464 259 post :create, :project => { :name => "blog",
Chris@1464 260 :description => "weblog",
Chris@1464 261 :identifier => "blog",
Chris@1464 262 :is_public => 1,
Chris@1464 263 :custom_field_values => { '3' => 'Beta' },
Chris@1464 264 :parent_id => 6
Chris@1464 265 }
Chris@1464 266 end
Chris@1464 267 assert_response :success
Chris@1464 268 project = assigns(:project)
Chris@1464 269 assert_kind_of Project, project
Chris@1464 270 assert_not_equal [], project.errors[:parent_id]
Chris@1464 271 end
Chris@1464 272
Chris@1464 273 def test_create_subproject_with_inherit_members_should_inherit_members
Chris@1464 274 Role.find_by_name('Manager').add_permission! :add_subprojects
Chris@1464 275 parent = Project.find(1)
Chris@1464 276 @request.session[:user_id] = 2
Chris@1464 277
Chris@1464 278 assert_difference 'Project.count' do
Chris@1464 279 post :create, :project => {
Chris@1464 280 :name => 'inherited', :identifier => 'inherited', :parent_id => parent.id, :inherit_members => '1'
Chris@1464 281 }
Chris@1464 282 assert_response 302
chris@22 283 end
chris@22 284
Chris@1464 285 project = Project.order('id desc').first
Chris@1464 286 assert_equal 'inherited', project.name
Chris@1464 287 assert_equal parent, project.parent
Chris@1464 288 assert project.memberships.count > 0
Chris@1464 289 assert_equal parent.memberships.count, project.memberships.count
Chris@0 290 end
Chris@441 291
Chris@441 292 def test_create_should_preserve_modules_on_validation_failure
Chris@441 293 with_settings :default_projects_modules => ['issue_tracking', 'repository'] do
Chris@441 294 @request.session[:user_id] = 1
Chris@441 295 assert_no_difference 'Project.count' do
Chris@441 296 post :create, :project => {
Chris@441 297 :name => "blog",
Chris@441 298 :identifier => "",
Chris@441 299 :enabled_module_names => %w(issue_tracking news)
Chris@441 300 }
Chris@441 301 end
Chris@441 302 assert_response :success
Chris@441 303 project = assigns(:project)
Chris@441 304 assert_equal %w(issue_tracking news), project.enabled_module_names.sort
Chris@441 305 end
Chris@441 306 end
Chris@441 307
Chris@0 308 def test_show_by_id
Chris@0 309 get :show, :id => 1
Chris@0 310 assert_response :success
Chris@0 311 assert_template 'show'
Chris@0 312 assert_not_nil assigns(:project)
Chris@0 313 end
Chris@0 314
Chris@0 315 def test_show_by_identifier
Chris@0 316 get :show, :id => 'ecookbook'
Chris@0 317 assert_response :success
Chris@0 318 assert_template 'show'
Chris@0 319 assert_not_nil assigns(:project)
Chris@0 320 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
Chris@441 321
Chris@1464 322 assert_select 'li', :text => /Development status/
Chris@1464 323 end
Chris@1464 324
Chris@1464 325 def test_show_should_not_display_empty_sidebar
Chris@1464 326 p = Project.find(1)
Chris@1464 327 p.enabled_module_names = []
Chris@1464 328 p.save!
Chris@1464 329
Chris@1464 330 get :show, :id => 'ecookbook'
Chris@1464 331 assert_response :success
Chris@1464 332 assert_select '#main.nosidebar'
chris@37 333 end
chris@37 334
chris@37 335 def test_show_should_not_display_hidden_custom_fields
chris@37 336 ProjectCustomField.find_by_name('Development status').update_attribute :visible, false
chris@37 337 get :show, :id => 'ecookbook'
chris@37 338 assert_response :success
chris@37 339 assert_template 'show'
chris@37 340 assert_not_nil assigns(:project)
Chris@441 341
Chris@1464 342 assert_select 'li', :text => /Development status/, :count => 0
Chris@0 343 end
Chris@441 344
Chris@0 345 def test_show_should_not_fail_when_custom_values_are_nil
Chris@0 346 project = Project.find_by_identifier('ecookbook')
Chris@0 347 project.custom_values.first.update_attribute(:value, nil)
Chris@0 348 get :show, :id => 'ecookbook'
Chris@0 349 assert_response :success
Chris@0 350 assert_template 'show'
Chris@0 351 assert_not_nil assigns(:project)
Chris@0 352 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
Chris@0 353 end
Chris@441 354
chris@37 355 def show_archived_project_should_be_denied
chris@37 356 project = Project.find_by_identifier('ecookbook')
chris@37 357 project.archive!
Chris@441 358
chris@37 359 get :show, :id => 'ecookbook'
chris@37 360 assert_response 403
chris@37 361 assert_nil assigns(:project)
Chris@1464 362 assert_select 'p', :text => /archived/
chris@37 363 end
Chris@441 364
Chris@1464 365 def test_show_should_not_show_private_subprojects_that_are_not_visible
Chris@0 366 get :show, :id => 'ecookbook'
Chris@0 367 assert_response :success
Chris@0 368 assert_template 'show'
Chris@1464 369 assert_select 'a', :text => /Private child/, :count => 0
Chris@0 370 end
Chris@0 371
Chris@1464 372 def test_show_should_show_private_subprojects_that_are_visible
Chris@0 373 @request.session[:user_id] = 2 # manager who is a member of the private subproject
Chris@0 374 get :show, :id => 'ecookbook'
Chris@0 375 assert_response :success
Chris@0 376 assert_template 'show'
Chris@1464 377 assert_select 'a', :text => /Private child/
Chris@0 378 end
Chris@441 379
Chris@0 380 def test_settings
Chris@0 381 @request.session[:user_id] = 2 # manager
Chris@0 382 get :settings, :id => 1
Chris@0 383 assert_response :success
Chris@0 384 assert_template 'settings'
Chris@0 385 end
Chris@441 386
Chris@1464 387 def test_settings_of_subproject
Chris@1464 388 @request.session[:user_id] = 2
Chris@1464 389 get :settings, :id => 'private-child'
Chris@1464 390 assert_response :success
Chris@1464 391 assert_template 'settings'
Chris@1464 392
Chris@1464 393 assert_select 'input[type=checkbox][name=?]', 'project[inherit_members]'
Chris@1464 394 end
Chris@1464 395
Chris@1115 396 def test_settings_should_be_denied_for_member_on_closed_project
Chris@1115 397 Project.find(1).close
Chris@1115 398 @request.session[:user_id] = 2 # manager
Chris@1115 399
Chris@1115 400 get :settings, :id => 1
Chris@1115 401 assert_response 403
Chris@1115 402 end
Chris@1115 403
Chris@1115 404 def test_settings_should_be_denied_for_anonymous_on_closed_project
Chris@1115 405 Project.find(1).close
Chris@1115 406
Chris@1115 407 get :settings, :id => 1
Chris@1115 408 assert_response 302
Chris@1115 409 end
Chris@1115 410
chris@22 411 def test_update
Chris@0 412 @request.session[:user_id] = 2 # manager
chris@22 413 post :update, :id => 1, :project => {:name => 'Test changed name',
Chris@0 414 :issue_custom_field_ids => ['']}
chris@37 415 assert_redirected_to '/projects/ecookbook/settings'
Chris@0 416 project = Project.find(1)
Chris@0 417 assert_equal 'Test changed name', project.name
Chris@0 418 end
Chris@119 419
Chris@1115 420 def test_update_with_failure
Chris@1115 421 @request.session[:user_id] = 2 # manager
Chris@1115 422 post :update, :id => 1, :project => {:name => ''}
Chris@1115 423 assert_response :success
Chris@1115 424 assert_template 'settings'
Chris@1517 425 assert_error_tag :content => /name #{ESCAPED_CANT} be blank/i
Chris@1115 426 end
Chris@1115 427
Chris@1115 428 def test_update_should_be_denied_for_member_on_closed_project
Chris@1115 429 Project.find(1).close
Chris@1115 430 @request.session[:user_id] = 2 # manager
Chris@1115 431
Chris@1115 432 post :update, :id => 1, :project => {:name => 'Closed'}
Chris@1115 433 assert_response 403
Chris@1115 434 assert_equal 'eCookbook', Project.find(1).name
Chris@1115 435 end
Chris@1115 436
Chris@1115 437 def test_update_should_be_denied_for_anonymous_on_closed_project
Chris@1115 438 Project.find(1).close
Chris@1115 439
Chris@1115 440 post :update, :id => 1, :project => {:name => 'Closed'}
Chris@1115 441 assert_response 302
Chris@1115 442 assert_equal 'eCookbook', Project.find(1).name
Chris@1115 443 end
Chris@1115 444
Chris@119 445 def test_modules
Chris@119 446 @request.session[:user_id] = 2
Chris@119 447 Project.find(1).enabled_module_names = ['issue_tracking', 'news']
Chris@441 448
Chris@119 449 post :modules, :id => 1, :enabled_module_names => ['issue_tracking', 'repository', 'documents']
Chris@119 450 assert_redirected_to '/projects/ecookbook/settings/modules'
Chris@119 451 assert_equal ['documents', 'issue_tracking', 'repository'], Project.find(1).enabled_module_names.sort
Chris@119 452 end
Chris@119 453
Chris@1464 454 def test_destroy_leaf_project_without_confirmation_should_show_confirmation
Chris@0 455 @request.session[:user_id] = 1 # admin
Chris@1464 456
Chris@1464 457 assert_no_difference 'Project.count' do
Chris@1464 458 delete :destroy, :id => 2
Chris@1464 459 assert_response :success
Chris@1464 460 assert_template 'destroy'
Chris@1464 461 end
Chris@1464 462 end
Chris@1464 463
Chris@1464 464 def test_destroy_without_confirmation_should_show_confirmation_with_subprojects
Chris@1464 465 @request.session[:user_id] = 1 # admin
Chris@1464 466
Chris@1464 467 assert_no_difference 'Project.count' do
Chris@1464 468 delete :destroy, :id => 1
Chris@1464 469 assert_response :success
Chris@1464 470 assert_template 'destroy'
Chris@1464 471 end
Chris@1464 472 assert_select 'strong',
Chris@1464 473 :text => ['Private child of eCookbook',
Chris@1115 474 'Child of private child, eCookbook Subproject 1',
Chris@1115 475 'eCookbook Subproject 2'].join(', ')
Chris@0 476 end
Chris@0 477
Chris@1464 478 def test_destroy_with_confirmation_should_destroy_the_project_and_subprojects
Chris@0 479 @request.session[:user_id] = 1 # admin
Chris@1464 480
Chris@1464 481 assert_difference 'Project.count', -5 do
Chris@1464 482 delete :destroy, :id => 1, :confirm => 1
Chris@1464 483 assert_redirected_to '/admin/projects'
Chris@1464 484 end
Chris@0 485 assert_nil Project.find_by_id(1)
Chris@0 486 end
Chris@441 487
Chris@0 488 def test_archive
Chris@0 489 @request.session[:user_id] = 1 # admin
Chris@0 490 post :archive, :id => 1
chris@37 491 assert_redirected_to '/admin/projects'
Chris@0 492 assert !Project.find(1).active?
Chris@0 493 end
Chris@441 494
Chris@1115 495 def test_archive_with_failure
Chris@1115 496 @request.session[:user_id] = 1
Chris@1115 497 Project.any_instance.stubs(:archive).returns(false)
Chris@1115 498 post :archive, :id => 1
Chris@1115 499 assert_redirected_to '/admin/projects'
Chris@1115 500 assert_match /project cannot be archived/i, flash[:error]
Chris@1115 501 end
Chris@1115 502
Chris@0 503 def test_unarchive
Chris@0 504 @request.session[:user_id] = 1 # admin
Chris@0 505 Project.find(1).archive
Chris@0 506 post :unarchive, :id => 1
chris@37 507 assert_redirected_to '/admin/projects'
Chris@0 508 assert Project.find(1).active?
Chris@0 509 end
Chris@441 510
Chris@1115 511 def test_close
Chris@1115 512 @request.session[:user_id] = 2
Chris@1115 513 post :close, :id => 1
Chris@1115 514 assert_redirected_to '/projects/ecookbook'
Chris@1115 515 assert_equal Project::STATUS_CLOSED, Project.find(1).status
Chris@1115 516 end
Chris@1115 517
Chris@1115 518 def test_reopen
Chris@1115 519 Project.find(1).close
Chris@1115 520 @request.session[:user_id] = 2
Chris@1115 521 post :reopen, :id => 1
Chris@1115 522 assert_redirected_to '/projects/ecookbook'
Chris@1115 523 assert Project.find(1).active?
Chris@1115 524 end
Chris@1115 525
Chris@0 526 def test_project_breadcrumbs_should_be_limited_to_3_ancestors
Chris@0 527 CustomField.delete_all
Chris@0 528 parent = nil
Chris@0 529 6.times do |i|
Chris@1464 530 p = Project.generate_with_parent!(parent)
Chris@0 531 get :show, :id => p
Chris@1464 532 assert_select '#header h1' do
Chris@1464 533 assert_select 'a', :count => [i, 3].min
Chris@1464 534 end
Chris@441 535
Chris@0 536 parent = p
Chris@0 537 end
Chris@0 538 end
Chris@0 539
Chris@441 540 def test_get_copy
Chris@0 541 @request.session[:user_id] = 1 # admin
Chris@0 542 get :copy, :id => 1
Chris@0 543 assert_response :success
Chris@0 544 assert_template 'copy'
Chris@0 545 assert assigns(:project)
Chris@0 546 assert_equal Project.find(1).description, assigns(:project).description
Chris@0 547 assert_nil assigns(:project).id
Chris@441 548
Chris@1464 549 assert_select 'input[name=?][value=?]', 'project[enabled_module_names][]', 'issue_tracking', 1
Chris@0 550 end
Chris@0 551
Chris@1115 552 def test_get_copy_with_invalid_source_should_respond_with_404
Chris@1115 553 @request.session[:user_id] = 1
Chris@1115 554 get :copy, :id => 99
Chris@1115 555 assert_response 404
Chris@0 556 end
Chris@0 557
Chris@441 558 def test_post_copy_should_copy_requested_items
Chris@441 559 @request.session[:user_id] = 1 # admin
Chris@441 560 CustomField.delete_all
chris@37 561
Chris@441 562 assert_difference 'Project.count' do
Chris@441 563 post :copy, :id => 1,
Chris@441 564 :project => {
Chris@441 565 :name => 'Copy',
Chris@441 566 :identifier => 'unique-copy',
Chris@441 567 :tracker_ids => ['1', '2', '3', ''],
Chris@441 568 :enabled_module_names => %w(issue_tracking time_tracking)
Chris@441 569 },
Chris@441 570 :only => %w(issues versions)
chris@37 571 end
Chris@441 572 project = Project.find('unique-copy')
Chris@441 573 source = Project.find(1)
Chris@441 574 assert_equal %w(issue_tracking time_tracking), project.enabled_module_names.sort
Chris@441 575
Chris@441 576 assert_equal source.versions.count, project.versions.count, "All versions were not copied"
Chris@1115 577 assert_equal source.issues.count, project.issues.count, "All issues were not copied"
Chris@441 578 assert_equal 0, project.members.count
Chris@441 579 end
Chris@441 580
Chris@441 581 def test_post_copy_should_redirect_to_settings_when_successful
Chris@441 582 @request.session[:user_id] = 1 # admin
Chris@441 583 post :copy, :id => 1, :project => {:name => 'Copy', :identifier => 'unique-copy'}
Chris@441 584 assert_response :redirect
Chris@441 585 assert_redirected_to :controller => 'projects', :action => 'settings', :id => 'unique-copy'
chris@37 586 end
chris@37 587
Chris@0 588 def test_jump_should_redirect_to_active_tab
Chris@0 589 get :show, :id => 1, :jump => 'issues'
chris@37 590 assert_redirected_to '/projects/ecookbook/issues'
Chris@0 591 end
Chris@441 592
Chris@0 593 def test_jump_should_not_redirect_to_inactive_tab
Chris@0 594 get :show, :id => 3, :jump => 'documents'
Chris@0 595 assert_response :success
Chris@0 596 assert_template 'show'
Chris@0 597 end
Chris@441 598
Chris@0 599 def test_jump_should_not_redirect_to_unknown_tab
Chris@0 600 get :show, :id => 3, :jump => 'foobar'
Chris@0 601 assert_response :success
Chris@0 602 assert_template 'show'
Chris@0 603 end
Chris@1464 604
Chris@1464 605 def test_body_should_have_project_css_class
Chris@1464 606 get :show, :id => 1
Chris@1464 607 assert_select 'body.project-ecookbook'
Chris@1464 608 end
Chris@0 609 end