annotate .svn/pristine/c6/c63c3cd61fc296170b8167aad5904de39c22ed23.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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