annotate test/functional/projects_controller_test.rb @ 1519:afce8026aaeb redmine-2.4-integration

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