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