annotate test/unit/project_test.rb @ 1174:928c0d0f624e bug_365

Close obsolete branch bug_365
author Chris Cannam
date Fri, 03 Feb 2012 14:03:51 +0000
parents 0c939c159af4
children cbb26bc654de
rev   line source
Chris@441 1 # Redmine - project management software
Chris@441 2 # Copyright (C) 2006-2011 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@0 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@0 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 ProjectTest < ActiveSupport::TestCase
Chris@0 21 fixtures :all
Chris@0 22
Chris@0 23 def setup
Chris@0 24 @ecookbook = Project.find(1)
Chris@0 25 @ecookbook_sub1 = Project.find(3)
Chris@0 26 User.current = nil
Chris@0 27 end
Chris@0 28
Chris@0 29 should_validate_presence_of :name
Chris@0 30 should_validate_presence_of :identifier
Chris@0 31
Chris@0 32 should_validate_uniqueness_of :identifier
Chris@0 33
Chris@0 34 context "associations" do
Chris@0 35 should_have_many :members
Chris@0 36 should_have_many :users, :through => :members
Chris@0 37 should_have_many :member_principals
Chris@0 38 should_have_many :principals, :through => :member_principals
Chris@0 39 should_have_many :enabled_modules
Chris@0 40 should_have_many :issues
Chris@0 41 should_have_many :issue_changes, :through => :issues
Chris@0 42 should_have_many :versions
Chris@0 43 should_have_many :time_entries
Chris@0 44 should_have_many :queries
Chris@0 45 should_have_many :documents
Chris@0 46 should_have_many :news
Chris@0 47 should_have_many :issue_categories
Chris@0 48 should_have_many :boards
Chris@0 49 should_have_many :changesets, :through => :repository
Chris@0 50
Chris@0 51 should_have_one :repository
Chris@0 52 should_have_one :wiki
Chris@0 53
Chris@0 54 should_have_and_belong_to_many :trackers
Chris@0 55 should_have_and_belong_to_many :issue_custom_fields
Chris@0 56 end
Chris@0 57
Chris@0 58 def test_truth
Chris@0 59 assert_kind_of Project, @ecookbook
Chris@0 60 assert_equal "eCookbook", @ecookbook.name
Chris@0 61 end
Chris@0 62
Chris@119 63 def test_default_attributes
Chris@119 64 with_settings :default_projects_public => '1' do
Chris@119 65 assert_equal true, Project.new.is_public
Chris@119 66 assert_equal false, Project.new(:is_public => false).is_public
Chris@119 67 end
Chris@119 68
Chris@119 69 with_settings :default_projects_public => '0' do
Chris@119 70 assert_equal false, Project.new.is_public
Chris@119 71 assert_equal true, Project.new(:is_public => true).is_public
Chris@119 72 end
Chris@119 73
Chris@119 74 with_settings :sequential_project_identifiers => '1' do
Chris@119 75 assert !Project.new.identifier.blank?
Chris@119 76 assert Project.new(:identifier => '').identifier.blank?
Chris@119 77 end
Chris@119 78
Chris@119 79 with_settings :sequential_project_identifiers => '0' do
Chris@119 80 assert Project.new.identifier.blank?
Chris@119 81 assert !Project.new(:identifier => 'test').blank?
Chris@119 82 end
Chris@119 83
Chris@119 84 with_settings :default_projects_modules => ['issue_tracking', 'repository'] do
Chris@119 85 assert_equal ['issue_tracking', 'repository'], Project.new.enabled_module_names
Chris@119 86 end
Chris@119 87
Chris@119 88 assert_equal Tracker.all, Project.new.trackers
Chris@119 89 assert_equal Tracker.find(1, 3), Project.new(:tracker_ids => [1, 3]).trackers
Chris@119 90 end
Chris@119 91
Chris@0 92 def test_update
Chris@0 93 assert_equal "eCookbook", @ecookbook.name
Chris@0 94 @ecookbook.name = "eCook"
Chris@0 95 assert @ecookbook.save, @ecookbook.errors.full_messages.join("; ")
Chris@0 96 @ecookbook.reload
Chris@0 97 assert_equal "eCook", @ecookbook.name
Chris@0 98 end
Chris@0 99
Chris@0 100 def test_validate_identifier
Chris@0 101 to_test = {"abc" => true,
Chris@0 102 "ab12" => true,
Chris@0 103 "ab-12" => true,
Chris@0 104 "12" => false,
Chris@0 105 "new" => false}
Chris@0 106
Chris@0 107 to_test.each do |identifier, valid|
Chris@0 108 p = Project.new
Chris@0 109 p.identifier = identifier
Chris@0 110 p.valid?
Chris@0 111 assert_equal valid, p.errors.on('identifier').nil?
Chris@0 112 end
Chris@0 113 end
Chris@0 114
Chris@0 115 def test_members_should_be_active_users
Chris@0 116 Project.all.each do |project|
Chris@0 117 assert_nil project.members.detect {|m| !(m.user.is_a?(User) && m.user.active?) }
Chris@0 118 end
Chris@0 119 end
Chris@0 120
Chris@0 121 def test_users_should_be_active_users
Chris@0 122 Project.all.each do |project|
Chris@0 123 assert_nil project.users.detect {|u| !(u.is_a?(User) && u.active?) }
Chris@0 124 end
Chris@0 125 end
Chris@0 126
Chris@0 127 def test_archive
Chris@0 128 user = @ecookbook.members.first.user
Chris@0 129 @ecookbook.archive
Chris@0 130 @ecookbook.reload
Chris@0 131
Chris@0 132 assert !@ecookbook.active?
chris@37 133 assert @ecookbook.archived?
Chris@0 134 assert !user.projects.include?(@ecookbook)
Chris@0 135 # Subproject are also archived
Chris@0 136 assert !@ecookbook.children.empty?
Chris@0 137 assert @ecookbook.descendants.active.empty?
Chris@0 138 end
Chris@0 139
Chris@0 140 def test_archive_should_fail_if_versions_are_used_by_non_descendant_projects
Chris@0 141 # Assign an issue of a project to a version of a child project
Chris@0 142 Issue.find(4).update_attribute :fixed_version_id, 4
Chris@0 143
Chris@0 144 assert_no_difference "Project.count(:all, :conditions => 'status = #{Project::STATUS_ARCHIVED}')" do
Chris@0 145 assert_equal false, @ecookbook.archive
Chris@0 146 end
Chris@0 147 @ecookbook.reload
Chris@0 148 assert @ecookbook.active?
Chris@0 149 end
Chris@0 150
Chris@0 151 def test_unarchive
Chris@0 152 user = @ecookbook.members.first.user
Chris@0 153 @ecookbook.archive
Chris@0 154 # A subproject of an archived project can not be unarchived
Chris@0 155 assert !@ecookbook_sub1.unarchive
Chris@0 156
Chris@0 157 # Unarchive project
Chris@0 158 assert @ecookbook.unarchive
Chris@0 159 @ecookbook.reload
Chris@0 160 assert @ecookbook.active?
chris@37 161 assert !@ecookbook.archived?
Chris@0 162 assert user.projects.include?(@ecookbook)
Chris@0 163 # Subproject can now be unarchived
Chris@0 164 @ecookbook_sub1.reload
Chris@0 165 assert @ecookbook_sub1.unarchive
Chris@0 166 end
Chris@0 167
Chris@0 168 def test_destroy
Chris@0 169 # 2 active members
Chris@0 170 assert_equal 2, @ecookbook.members.size
Chris@0 171 # and 1 is locked
Chris@0 172 assert_equal 3, Member.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).size
Chris@0 173 # some boards
Chris@0 174 assert @ecookbook.boards.any?
Chris@0 175
Chris@0 176 @ecookbook.destroy
Chris@0 177 # make sure that the project non longer exists
Chris@0 178 assert_raise(ActiveRecord::RecordNotFound) { Project.find(@ecookbook.id) }
Chris@0 179 # make sure related data was removed
Chris@0 180 assert_nil Member.first(:conditions => {:project_id => @ecookbook.id})
Chris@0 181 assert_nil Board.first(:conditions => {:project_id => @ecookbook.id})
Chris@0 182 assert_nil Issue.first(:conditions => {:project_id => @ecookbook.id})
Chris@0 183 end
Chris@0 184
Chris@441 185 def test_destroying_root_projects_should_clear_data
Chris@441 186 Project.roots.each do |root|
Chris@441 187 root.destroy
Chris@441 188 end
Chris@441 189
Chris@441 190 assert_equal 0, Project.count, "Projects were not deleted: #{Project.all.inspect}"
Chris@441 191 assert_equal 0, Member.count, "Members were not deleted: #{Member.all.inspect}"
Chris@441 192 assert_equal 0, MemberRole.count
Chris@441 193 assert_equal 0, Issue.count
Chris@441 194 assert_equal 0, Journal.count
Chris@441 195 assert_equal 0, JournalDetail.count
Chris@441 196 assert_equal 0, Attachment.count
Chris@441 197 assert_equal 0, EnabledModule.count
Chris@441 198 assert_equal 0, IssueCategory.count
Chris@441 199 assert_equal 0, IssueRelation.count
Chris@441 200 assert_equal 0, Board.count
Chris@441 201 assert_equal 0, Message.count
Chris@441 202 assert_equal 0, News.count
Chris@441 203 assert_equal 0, Query.count(:conditions => "project_id IS NOT NULL")
Chris@441 204 assert_equal 0, Repository.count
Chris@441 205 assert_equal 0, Changeset.count
Chris@441 206 assert_equal 0, Change.count
Chris@441 207 assert_equal 0, Comment.count
Chris@441 208 assert_equal 0, TimeEntry.count
Chris@441 209 assert_equal 0, Version.count
Chris@441 210 assert_equal 0, Watcher.count
Chris@441 211 assert_equal 0, Wiki.count
Chris@441 212 assert_equal 0, WikiPage.count
Chris@441 213 assert_equal 0, WikiContent.count
Chris@441 214 assert_equal 0, WikiContent::Version.count
Chris@441 215 assert_equal 0, Project.connection.select_all("SELECT * FROM projects_trackers").size
Chris@441 216 assert_equal 0, Project.connection.select_all("SELECT * FROM custom_fields_projects").size
Chris@441 217 assert_equal 0, CustomValue.count(:conditions => {:customized_type => ['Project', 'Issue', 'TimeEntry', 'Version']})
Chris@441 218 end
Chris@441 219
Chris@0 220 def test_move_an_orphan_project_to_a_root_project
Chris@0 221 sub = Project.find(2)
Chris@0 222 sub.set_parent! @ecookbook
Chris@0 223 assert_equal @ecookbook.id, sub.parent.id
Chris@0 224 @ecookbook.reload
Chris@0 225 assert_equal 4, @ecookbook.children.size
Chris@0 226 end
Chris@0 227
Chris@0 228 def test_move_an_orphan_project_to_a_subproject
Chris@0 229 sub = Project.find(2)
Chris@0 230 assert sub.set_parent!(@ecookbook_sub1)
Chris@0 231 end
Chris@0 232
Chris@0 233 def test_move_a_root_project_to_a_project
Chris@0 234 sub = @ecookbook
Chris@0 235 assert sub.set_parent!(Project.find(2))
Chris@0 236 end
Chris@0 237
Chris@0 238 def test_should_not_move_a_project_to_its_children
Chris@0 239 sub = @ecookbook
Chris@0 240 assert !(sub.set_parent!(Project.find(3)))
Chris@0 241 end
Chris@0 242
Chris@0 243 def test_set_parent_should_add_roots_in_alphabetical_order
Chris@0 244 ProjectCustomField.delete_all
Chris@0 245 Project.delete_all
Chris@0 246 Project.create!(:name => 'Project C', :identifier => 'project-c').set_parent!(nil)
Chris@0 247 Project.create!(:name => 'Project B', :identifier => 'project-b').set_parent!(nil)
Chris@0 248 Project.create!(:name => 'Project D', :identifier => 'project-d').set_parent!(nil)
Chris@0 249 Project.create!(:name => 'Project A', :identifier => 'project-a').set_parent!(nil)
Chris@0 250
Chris@0 251 assert_equal 4, Project.count
Chris@0 252 assert_equal Project.all.sort_by(&:name), Project.all.sort_by(&:lft)
Chris@0 253 end
Chris@0 254
Chris@0 255 def test_set_parent_should_add_children_in_alphabetical_order
Chris@0 256 ProjectCustomField.delete_all
Chris@0 257 parent = Project.create!(:name => 'Parent', :identifier => 'parent')
Chris@0 258 Project.create!(:name => 'Project C', :identifier => 'project-c').set_parent!(parent)
Chris@0 259 Project.create!(:name => 'Project B', :identifier => 'project-b').set_parent!(parent)
Chris@0 260 Project.create!(:name => 'Project D', :identifier => 'project-d').set_parent!(parent)
Chris@0 261 Project.create!(:name => 'Project A', :identifier => 'project-a').set_parent!(parent)
Chris@0 262
Chris@0 263 parent.reload
Chris@0 264 assert_equal 4, parent.children.size
Chris@0 265 assert_equal parent.children.sort_by(&:name), parent.children
Chris@0 266 end
Chris@0 267
Chris@0 268 def test_rebuild_should_sort_children_alphabetically
Chris@0 269 ProjectCustomField.delete_all
Chris@0 270 parent = Project.create!(:name => 'Parent', :identifier => 'parent')
Chris@0 271 Project.create!(:name => 'Project C', :identifier => 'project-c').move_to_child_of(parent)
Chris@0 272 Project.create!(:name => 'Project B', :identifier => 'project-b').move_to_child_of(parent)
Chris@0 273 Project.create!(:name => 'Project D', :identifier => 'project-d').move_to_child_of(parent)
Chris@0 274 Project.create!(:name => 'Project A', :identifier => 'project-a').move_to_child_of(parent)
Chris@0 275
Chris@0 276 Project.update_all("lft = NULL, rgt = NULL")
Chris@0 277 Project.rebuild!
Chris@0 278
Chris@0 279 parent.reload
Chris@0 280 assert_equal 4, parent.children.size
Chris@0 281 assert_equal parent.children.sort_by(&:name), parent.children
Chris@0 282 end
Chris@0 283
Chris@0 284
Chris@0 285 def test_set_parent_should_update_issue_fixed_version_associations_when_a_fixed_version_is_moved_out_of_the_hierarchy
Chris@0 286 # Parent issue with a hierarchy project's fixed version
Chris@0 287 parent_issue = Issue.find(1)
Chris@0 288 parent_issue.update_attribute(:fixed_version_id, 4)
Chris@0 289 parent_issue.reload
Chris@0 290 assert_equal 4, parent_issue.fixed_version_id
Chris@0 291
Chris@0 292 # Should keep fixed versions for the issues
Chris@0 293 issue_with_local_fixed_version = Issue.find(5)
Chris@0 294 issue_with_local_fixed_version.update_attribute(:fixed_version_id, 4)
Chris@0 295 issue_with_local_fixed_version.reload
Chris@0 296 assert_equal 4, issue_with_local_fixed_version.fixed_version_id
Chris@0 297
Chris@0 298 # Local issue with hierarchy fixed_version
Chris@0 299 issue_with_hierarchy_fixed_version = Issue.find(13)
Chris@0 300 issue_with_hierarchy_fixed_version.update_attribute(:fixed_version_id, 6)
Chris@0 301 issue_with_hierarchy_fixed_version.reload
Chris@0 302 assert_equal 6, issue_with_hierarchy_fixed_version.fixed_version_id
Chris@0 303
Chris@0 304 # Move project out of the issue's hierarchy
Chris@0 305 moved_project = Project.find(3)
Chris@0 306 moved_project.set_parent!(Project.find(2))
Chris@0 307 parent_issue.reload
Chris@0 308 issue_with_local_fixed_version.reload
Chris@0 309 issue_with_hierarchy_fixed_version.reload
Chris@0 310
Chris@0 311 assert_equal 4, issue_with_local_fixed_version.fixed_version_id, "Fixed version was not keep on an issue local to the moved project"
Chris@0 312 assert_equal nil, issue_with_hierarchy_fixed_version.fixed_version_id, "Fixed version is still set after moving the Project out of the hierarchy where the version is defined in"
Chris@0 313 assert_equal nil, parent_issue.fixed_version_id, "Fixed version is still set after moving the Version out of the hierarchy for the issue."
Chris@0 314 end
Chris@0 315
Chris@0 316 def test_parent
Chris@0 317 p = Project.find(6).parent
Chris@0 318 assert p.is_a?(Project)
Chris@0 319 assert_equal 5, p.id
Chris@0 320 end
Chris@0 321
Chris@0 322 def test_ancestors
Chris@0 323 a = Project.find(6).ancestors
Chris@0 324 assert a.first.is_a?(Project)
Chris@0 325 assert_equal [1, 5], a.collect(&:id)
Chris@0 326 end
Chris@0 327
Chris@0 328 def test_root
Chris@0 329 r = Project.find(6).root
Chris@0 330 assert r.is_a?(Project)
Chris@0 331 assert_equal 1, r.id
Chris@0 332 end
Chris@0 333
Chris@0 334 def test_children
Chris@0 335 c = Project.find(1).children
Chris@0 336 assert c.first.is_a?(Project)
Chris@0 337 assert_equal [5, 3, 4], c.collect(&:id)
Chris@0 338 end
Chris@0 339
Chris@0 340 def test_descendants
Chris@0 341 d = Project.find(1).descendants
Chris@0 342 assert d.first.is_a?(Project)
Chris@0 343 assert_equal [5, 6, 3, 4], d.collect(&:id)
Chris@0 344 end
Chris@0 345
Chris@0 346 def test_allowed_parents_should_be_empty_for_non_member_user
Chris@0 347 Role.non_member.add_permission!(:add_project)
Chris@0 348 user = User.find(9)
Chris@0 349 assert user.memberships.empty?
Chris@0 350 User.current = user
Chris@0 351 assert Project.new.allowed_parents.compact.empty?
Chris@0 352 end
Chris@0 353
Chris@0 354 def test_allowed_parents_with_add_subprojects_permission
Chris@0 355 Role.find(1).remove_permission!(:add_project)
Chris@0 356 Role.find(1).add_permission!(:add_subprojects)
Chris@0 357 User.current = User.find(2)
Chris@0 358 # new project
Chris@0 359 assert !Project.new.allowed_parents.include?(nil)
Chris@0 360 assert Project.new.allowed_parents.include?(Project.find(1))
Chris@0 361 # existing root project
Chris@0 362 assert Project.find(1).allowed_parents.include?(nil)
Chris@0 363 # existing child
Chris@0 364 assert Project.find(3).allowed_parents.include?(Project.find(1))
Chris@0 365 assert !Project.find(3).allowed_parents.include?(nil)
Chris@0 366 end
Chris@0 367
Chris@0 368 def test_allowed_parents_with_add_project_permission
Chris@0 369 Role.find(1).add_permission!(:add_project)
Chris@0 370 Role.find(1).remove_permission!(:add_subprojects)
Chris@0 371 User.current = User.find(2)
Chris@0 372 # new project
Chris@0 373 assert Project.new.allowed_parents.include?(nil)
Chris@0 374 assert !Project.new.allowed_parents.include?(Project.find(1))
Chris@0 375 # existing root project
Chris@0 376 assert Project.find(1).allowed_parents.include?(nil)
Chris@0 377 # existing child
Chris@0 378 assert Project.find(3).allowed_parents.include?(Project.find(1))
Chris@0 379 assert Project.find(3).allowed_parents.include?(nil)
Chris@0 380 end
Chris@0 381
Chris@0 382 def test_allowed_parents_with_add_project_and_subprojects_permission
Chris@0 383 Role.find(1).add_permission!(:add_project)
Chris@0 384 Role.find(1).add_permission!(:add_subprojects)
Chris@0 385 User.current = User.find(2)
Chris@0 386 # new project
Chris@0 387 assert Project.new.allowed_parents.include?(nil)
Chris@0 388 assert Project.new.allowed_parents.include?(Project.find(1))
Chris@0 389 # existing root project
Chris@0 390 assert Project.find(1).allowed_parents.include?(nil)
Chris@0 391 # existing child
Chris@0 392 assert Project.find(3).allowed_parents.include?(Project.find(1))
Chris@0 393 assert Project.find(3).allowed_parents.include?(nil)
Chris@0 394 end
Chris@0 395
Chris@0 396 def test_users_by_role
Chris@0 397 users_by_role = Project.find(1).users_by_role
Chris@0 398 assert_kind_of Hash, users_by_role
Chris@0 399 role = Role.find(1)
Chris@0 400 assert_kind_of Array, users_by_role[role]
Chris@0 401 assert users_by_role[role].include?(User.find(2))
Chris@0 402 end
Chris@0 403
Chris@0 404 def test_rolled_up_trackers
Chris@0 405 parent = Project.find(1)
Chris@0 406 parent.trackers = Tracker.find([1,2])
Chris@0 407 child = parent.children.find(3)
Chris@0 408
Chris@0 409 assert_equal [1, 2], parent.tracker_ids
Chris@0 410 assert_equal [2, 3], child.trackers.collect(&:id)
Chris@0 411
Chris@0 412 assert_kind_of Tracker, parent.rolled_up_trackers.first
Chris@0 413 assert_equal Tracker.find(1), parent.rolled_up_trackers.first
Chris@0 414
Chris@0 415 assert_equal [1, 2, 3], parent.rolled_up_trackers.collect(&:id)
Chris@0 416 assert_equal [2, 3], child.rolled_up_trackers.collect(&:id)
Chris@0 417 end
Chris@0 418
Chris@0 419 def test_rolled_up_trackers_should_ignore_archived_subprojects
Chris@0 420 parent = Project.find(1)
Chris@0 421 parent.trackers = Tracker.find([1,2])
Chris@0 422 child = parent.children.find(3)
Chris@0 423 child.trackers = Tracker.find([1,3])
Chris@0 424 parent.children.each(&:archive)
Chris@0 425
Chris@0 426 assert_equal [1,2], parent.rolled_up_trackers.collect(&:id)
Chris@0 427 end
Chris@0 428
Chris@0 429 context "#rolled_up_versions" do
Chris@0 430 setup do
Chris@0 431 @project = Project.generate!
Chris@0 432 @parent_version_1 = Version.generate!(:project => @project)
Chris@0 433 @parent_version_2 = Version.generate!(:project => @project)
Chris@0 434 end
Chris@0 435
Chris@0 436 should "include the versions for the current project" do
Chris@0 437 assert_same_elements [@parent_version_1, @parent_version_2], @project.rolled_up_versions
Chris@0 438 end
Chris@0 439
Chris@0 440 should "include versions for a subproject" do
Chris@0 441 @subproject = Project.generate!
Chris@0 442 @subproject.set_parent!(@project)
Chris@0 443 @subproject_version = Version.generate!(:project => @subproject)
Chris@0 444
Chris@0 445 assert_same_elements [
Chris@0 446 @parent_version_1,
Chris@0 447 @parent_version_2,
Chris@0 448 @subproject_version
Chris@0 449 ], @project.rolled_up_versions
Chris@0 450 end
Chris@0 451
Chris@0 452 should "include versions for a sub-subproject" do
Chris@0 453 @subproject = Project.generate!
Chris@0 454 @subproject.set_parent!(@project)
Chris@0 455 @sub_subproject = Project.generate!
Chris@0 456 @sub_subproject.set_parent!(@subproject)
Chris@0 457 @sub_subproject_version = Version.generate!(:project => @sub_subproject)
Chris@0 458
Chris@0 459 @project.reload
Chris@0 460
Chris@0 461 assert_same_elements [
Chris@0 462 @parent_version_1,
Chris@0 463 @parent_version_2,
Chris@0 464 @sub_subproject_version
Chris@0 465 ], @project.rolled_up_versions
Chris@0 466 end
Chris@0 467
Chris@0 468
Chris@0 469 should "only check active projects" do
Chris@0 470 @subproject = Project.generate!
Chris@0 471 @subproject.set_parent!(@project)
Chris@0 472 @subproject_version = Version.generate!(:project => @subproject)
Chris@0 473 assert @subproject.archive
Chris@0 474
Chris@0 475 @project.reload
Chris@0 476
Chris@0 477 assert !@subproject.active?
Chris@0 478 assert_same_elements [@parent_version_1, @parent_version_2], @project.rolled_up_versions
Chris@0 479 end
Chris@0 480 end
Chris@0 481
Chris@0 482 def test_shared_versions_none_sharing
Chris@0 483 p = Project.find(5)
Chris@0 484 v = Version.create!(:name => 'none_sharing', :project => p, :sharing => 'none')
Chris@0 485 assert p.shared_versions.include?(v)
Chris@0 486 assert !p.children.first.shared_versions.include?(v)
Chris@0 487 assert !p.root.shared_versions.include?(v)
Chris@0 488 assert !p.siblings.first.shared_versions.include?(v)
Chris@0 489 assert !p.root.siblings.first.shared_versions.include?(v)
Chris@0 490 end
Chris@0 491
Chris@0 492 def test_shared_versions_descendants_sharing
Chris@0 493 p = Project.find(5)
Chris@0 494 v = Version.create!(:name => 'descendants_sharing', :project => p, :sharing => 'descendants')
Chris@0 495 assert p.shared_versions.include?(v)
Chris@0 496 assert p.children.first.shared_versions.include?(v)
Chris@0 497 assert !p.root.shared_versions.include?(v)
Chris@0 498 assert !p.siblings.first.shared_versions.include?(v)
Chris@0 499 assert !p.root.siblings.first.shared_versions.include?(v)
Chris@0 500 end
Chris@0 501
Chris@0 502 def test_shared_versions_hierarchy_sharing
Chris@0 503 p = Project.find(5)
Chris@0 504 v = Version.create!(:name => 'hierarchy_sharing', :project => p, :sharing => 'hierarchy')
Chris@0 505 assert p.shared_versions.include?(v)
Chris@0 506 assert p.children.first.shared_versions.include?(v)
Chris@0 507 assert p.root.shared_versions.include?(v)
Chris@0 508 assert !p.siblings.first.shared_versions.include?(v)
Chris@0 509 assert !p.root.siblings.first.shared_versions.include?(v)
Chris@0 510 end
Chris@0 511
Chris@0 512 def test_shared_versions_tree_sharing
Chris@0 513 p = Project.find(5)
Chris@0 514 v = Version.create!(:name => 'tree_sharing', :project => p, :sharing => 'tree')
Chris@0 515 assert p.shared_versions.include?(v)
Chris@0 516 assert p.children.first.shared_versions.include?(v)
Chris@0 517 assert p.root.shared_versions.include?(v)
Chris@0 518 assert p.siblings.first.shared_versions.include?(v)
Chris@0 519 assert !p.root.siblings.first.shared_versions.include?(v)
Chris@0 520 end
Chris@0 521
Chris@0 522 def test_shared_versions_system_sharing
Chris@0 523 p = Project.find(5)
Chris@0 524 v = Version.create!(:name => 'system_sharing', :project => p, :sharing => 'system')
Chris@0 525 assert p.shared_versions.include?(v)
Chris@0 526 assert p.children.first.shared_versions.include?(v)
Chris@0 527 assert p.root.shared_versions.include?(v)
Chris@0 528 assert p.siblings.first.shared_versions.include?(v)
Chris@0 529 assert p.root.siblings.first.shared_versions.include?(v)
Chris@0 530 end
Chris@0 531
Chris@0 532 def test_shared_versions
Chris@0 533 parent = Project.find(1)
Chris@0 534 child = parent.children.find(3)
Chris@0 535 private_child = parent.children.find(5)
Chris@0 536
Chris@0 537 assert_equal [1,2,3], parent.version_ids.sort
Chris@0 538 assert_equal [4], child.version_ids
Chris@0 539 assert_equal [6], private_child.version_ids
Chris@0 540 assert_equal [7], Version.find_all_by_sharing('system').collect(&:id)
Chris@0 541
Chris@0 542 assert_equal 6, parent.shared_versions.size
Chris@0 543 parent.shared_versions.each do |version|
Chris@0 544 assert_kind_of Version, version
Chris@0 545 end
Chris@0 546
Chris@0 547 assert_equal [1,2,3,4,6,7], parent.shared_versions.collect(&:id).sort
Chris@0 548 end
Chris@0 549
Chris@0 550 def test_shared_versions_should_ignore_archived_subprojects
Chris@0 551 parent = Project.find(1)
Chris@0 552 child = parent.children.find(3)
Chris@0 553 child.archive
Chris@0 554 parent.reload
Chris@0 555
Chris@0 556 assert_equal [1,2,3], parent.version_ids.sort
Chris@0 557 assert_equal [4], child.version_ids
Chris@0 558 assert !parent.shared_versions.collect(&:id).include?(4)
Chris@0 559 end
Chris@0 560
Chris@0 561 def test_shared_versions_visible_to_user
Chris@0 562 user = User.find(3)
Chris@0 563 parent = Project.find(1)
Chris@0 564 child = parent.children.find(5)
Chris@0 565
Chris@0 566 assert_equal [1,2,3], parent.version_ids.sort
Chris@0 567 assert_equal [6], child.version_ids
Chris@0 568
Chris@0 569 versions = parent.shared_versions.visible(user)
Chris@0 570
Chris@0 571 assert_equal 4, versions.size
Chris@0 572 versions.each do |version|
Chris@0 573 assert_kind_of Version, version
Chris@0 574 end
Chris@0 575
Chris@0 576 assert !versions.collect(&:id).include?(6)
Chris@0 577 end
Chris@0 578
Chris@0 579
Chris@0 580 def test_next_identifier
Chris@0 581 ProjectCustomField.delete_all
Chris@0 582 Project.create!(:name => 'last', :identifier => 'p2008040')
Chris@0 583 assert_equal 'p2008041', Project.next_identifier
Chris@0 584 end
Chris@0 585
Chris@0 586 def test_next_identifier_first_project
Chris@0 587 Project.delete_all
Chris@0 588 assert_nil Project.next_identifier
Chris@0 589 end
Chris@0 590
Chris@441 591 def test_enabled_module_names
Chris@441 592 with_settings :default_projects_modules => ['issue_tracking', 'repository'] do
Chris@441 593 project = Project.new
Chris@441 594
Chris@441 595 project.enabled_module_names = %w(issue_tracking news)
Chris@441 596 assert_equal %w(issue_tracking news), project.enabled_module_names.sort
Chris@441 597 end
Chris@441 598 end
Chris@0 599
Chris@507 600 context "enabled_modules" do
Chris@507 601 setup do
Chris@507 602 @project = Project.find(1)
Chris@507 603 end
Chris@507 604
Chris@507 605 should "define module by names and preserve ids" do
Chris@507 606 # Remove one module
Chris@507 607 modules = @project.enabled_modules.slice(0..-2)
Chris@507 608 assert modules.any?
Chris@507 609 assert_difference 'EnabledModule.count', -1 do
Chris@507 610 @project.enabled_module_names = modules.collect(&:name)
Chris@507 611 end
Chris@507 612 @project.reload
Chris@507 613 # Ids should be preserved
Chris@507 614 assert_equal @project.enabled_module_ids.sort, modules.collect(&:id).sort
Chris@507 615 end
Chris@507 616
Chris@507 617 should "enable a module" do
Chris@507 618 @project.enabled_module_names = []
Chris@507 619 @project.reload
Chris@507 620 assert_equal [], @project.enabled_module_names
Chris@507 621 #with string
Chris@507 622 @project.enable_module!("issue_tracking")
Chris@507 623 assert_equal ["issue_tracking"], @project.enabled_module_names
Chris@507 624 #with symbol
Chris@507 625 @project.enable_module!(:gantt)
Chris@507 626 assert_equal ["issue_tracking", "gantt"], @project.enabled_module_names
Chris@507 627 #don't add a module twice
Chris@507 628 @project.enable_module!("issue_tracking")
Chris@507 629 assert_equal ["issue_tracking", "gantt"], @project.enabled_module_names
Chris@507 630 end
Chris@507 631
Chris@507 632 should "disable a module" do
Chris@507 633 #with string
Chris@507 634 assert @project.enabled_module_names.include?("issue_tracking")
Chris@507 635 @project.disable_module!("issue_tracking")
Chris@507 636 assert ! @project.reload.enabled_module_names.include?("issue_tracking")
Chris@507 637 #with symbol
Chris@507 638 assert @project.enabled_module_names.include?("gantt")
Chris@507 639 @project.disable_module!(:gantt)
Chris@507 640 assert ! @project.reload.enabled_module_names.include?("gantt")
Chris@507 641 #with EnabledModule object
Chris@507 642 first_module = @project.enabled_modules.first
Chris@507 643 @project.disable_module!(first_module)
Chris@507 644 assert ! @project.reload.enabled_module_names.include?(first_module.name)
Chris@507 645 end
Chris@507 646 end
Chris@507 647
Chris@0 648 def test_enabled_module_names_should_not_recreate_enabled_modules
Chris@0 649 project = Project.find(1)
Chris@0 650 # Remove one module
Chris@0 651 modules = project.enabled_modules.slice(0..-2)
Chris@0 652 assert modules.any?
Chris@0 653 assert_difference 'EnabledModule.count', -1 do
Chris@0 654 project.enabled_module_names = modules.collect(&:name)
Chris@0 655 end
Chris@0 656 project.reload
Chris@0 657 # Ids should be preserved
Chris@0 658 assert_equal project.enabled_module_ids.sort, modules.collect(&:id).sort
Chris@0 659 end
Chris@0 660
Chris@0 661 def test_copy_from_existing_project
Chris@0 662 source_project = Project.find(1)
Chris@0 663 copied_project = Project.copy_from(1)
Chris@0 664
Chris@0 665 assert copied_project
Chris@0 666 # Cleared attributes
Chris@0 667 assert copied_project.id.blank?
Chris@0 668 assert copied_project.name.blank?
Chris@0 669 assert copied_project.identifier.blank?
Chris@0 670
Chris@0 671 # Duplicated attributes
Chris@0 672 assert_equal source_project.description, copied_project.description
Chris@0 673 assert_equal source_project.enabled_modules, copied_project.enabled_modules
Chris@0 674 assert_equal source_project.trackers, copied_project.trackers
Chris@0 675
Chris@0 676 # Default attributes
Chris@0 677 assert_equal 1, copied_project.status
Chris@0 678 end
Chris@0 679
Chris@0 680 def test_activities_should_use_the_system_activities
Chris@0 681 project = Project.find(1)
Chris@0 682 assert_equal project.activities, TimeEntryActivity.find(:all, :conditions => {:active => true} )
Chris@0 683 end
Chris@0 684
Chris@0 685
Chris@0 686 def test_activities_should_use_the_project_specific_activities
Chris@0 687 project = Project.find(1)
Chris@0 688 overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project})
Chris@0 689 assert overridden_activity.save!
Chris@0 690
Chris@0 691 assert project.activities.include?(overridden_activity), "Project specific Activity not found"
Chris@0 692 end
Chris@0 693
Chris@0 694 def test_activities_should_not_include_the_inactive_project_specific_activities
Chris@0 695 project = Project.find(1)
Chris@0 696 overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => TimeEntryActivity.find(:first), :active => false})
Chris@0 697 assert overridden_activity.save!
Chris@0 698
Chris@0 699 assert !project.activities.include?(overridden_activity), "Inactive Project specific Activity found"
Chris@0 700 end
Chris@0 701
Chris@0 702 def test_activities_should_not_include_project_specific_activities_from_other_projects
Chris@0 703 project = Project.find(1)
Chris@0 704 overridden_activity = TimeEntryActivity.new({:name => "Project", :project => Project.find(2)})
Chris@0 705 assert overridden_activity.save!
Chris@0 706
Chris@0 707 assert !project.activities.include?(overridden_activity), "Project specific Activity found on a different project"
Chris@0 708 end
Chris@0 709
Chris@0 710 def test_activities_should_handle_nils
Chris@0 711 overridden_activity = TimeEntryActivity.new({:name => "Project", :project => Project.find(1), :parent => TimeEntryActivity.find(:first)})
Chris@0 712 TimeEntryActivity.delete_all
Chris@0 713
Chris@0 714 # No activities
Chris@0 715 project = Project.find(1)
Chris@0 716 assert project.activities.empty?
Chris@0 717
Chris@0 718 # No system, one overridden
Chris@0 719 assert overridden_activity.save!
Chris@0 720 project.reload
Chris@0 721 assert_equal [overridden_activity], project.activities
Chris@0 722 end
Chris@0 723
Chris@0 724 def test_activities_should_override_system_activities_with_project_activities
Chris@0 725 project = Project.find(1)
Chris@0 726 parent_activity = TimeEntryActivity.find(:first)
Chris@0 727 overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => parent_activity})
Chris@0 728 assert overridden_activity.save!
Chris@0 729
Chris@0 730 assert project.activities.include?(overridden_activity), "Project specific Activity not found"
Chris@0 731 assert !project.activities.include?(parent_activity), "System Activity found when it should have been overridden"
Chris@0 732 end
Chris@0 733
Chris@0 734 def test_activities_should_include_inactive_activities_if_specified
Chris@0 735 project = Project.find(1)
Chris@0 736 overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => TimeEntryActivity.find(:first), :active => false})
Chris@0 737 assert overridden_activity.save!
Chris@0 738
Chris@0 739 assert project.activities(true).include?(overridden_activity), "Inactive Project specific Activity not found"
Chris@0 740 end
Chris@0 741
Chris@0 742 test 'activities should not include active System activities if the project has an override that is inactive' do
Chris@0 743 project = Project.find(1)
Chris@0 744 system_activity = TimeEntryActivity.find_by_name('Design')
Chris@0 745 assert system_activity.active?
Chris@0 746 overridden_activity = TimeEntryActivity.generate!(:project => project, :parent => system_activity, :active => false)
Chris@0 747 assert overridden_activity.save!
Chris@0 748
Chris@0 749 assert !project.activities.include?(overridden_activity), "Inactive Project specific Activity not found"
Chris@0 750 assert !project.activities.include?(system_activity), "System activity found when the project has an inactive override"
Chris@0 751 end
Chris@0 752
Chris@0 753 def test_close_completed_versions
Chris@0 754 Version.update_all("status = 'open'")
Chris@0 755 project = Project.find(1)
Chris@0 756 assert_not_nil project.versions.detect {|v| v.completed? && v.status == 'open'}
Chris@0 757 assert_not_nil project.versions.detect {|v| !v.completed? && v.status == 'open'}
Chris@0 758 project.close_completed_versions
Chris@0 759 project.reload
Chris@0 760 assert_nil project.versions.detect {|v| v.completed? && v.status != 'closed'}
Chris@0 761 assert_not_nil project.versions.detect {|v| !v.completed? && v.status == 'open'}
Chris@0 762 end
Chris@0 763
Chris@0 764 context "Project#copy" do
Chris@0 765 setup do
Chris@0 766 ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests
Chris@0 767 Project.destroy_all :identifier => "copy-test"
Chris@0 768 @source_project = Project.find(2)
Chris@0 769 @project = Project.new(:name => 'Copy Test', :identifier => 'copy-test')
Chris@0 770 @project.trackers = @source_project.trackers
Chris@0 771 @project.enabled_module_names = @source_project.enabled_modules.collect(&:name)
Chris@0 772 end
Chris@0 773
Chris@0 774 should "copy issues" do
Chris@0 775 @source_project.issues << Issue.generate!(:status => IssueStatus.find_by_name('Closed'),
Chris@0 776 :subject => "copy issue status",
Chris@0 777 :tracker_id => 1,
Chris@0 778 :assigned_to_id => 2,
Chris@0 779 :project_id => @source_project.id)
Chris@0 780 assert @project.valid?
Chris@0 781 assert @project.issues.empty?
Chris@0 782 assert @project.copy(@source_project)
Chris@0 783
Chris@0 784 assert_equal @source_project.issues.size, @project.issues.size
Chris@0 785 @project.issues.each do |issue|
Chris@0 786 assert issue.valid?
Chris@0 787 assert ! issue.assigned_to.blank?
Chris@0 788 assert_equal @project, issue.project
Chris@0 789 end
Chris@0 790
Chris@0 791 copied_issue = @project.issues.first(:conditions => {:subject => "copy issue status"})
Chris@0 792 assert copied_issue
Chris@0 793 assert copied_issue.status
Chris@0 794 assert_equal "Closed", copied_issue.status.name
Chris@0 795 end
Chris@0 796
Chris@0 797 should "change the new issues to use the copied version" do
Chris@0 798 User.current = User.find(1)
Chris@0 799 assigned_version = Version.generate!(:name => "Assigned Issues", :status => 'open')
Chris@0 800 @source_project.versions << assigned_version
Chris@0 801 assert_equal 3, @source_project.versions.size
Chris@0 802 Issue.generate_for_project!(@source_project,
Chris@0 803 :fixed_version_id => assigned_version.id,
Chris@0 804 :subject => "change the new issues to use the copied version",
Chris@0 805 :tracker_id => 1,
Chris@0 806 :project_id => @source_project.id)
Chris@0 807
Chris@0 808 assert @project.copy(@source_project)
Chris@0 809 @project.reload
Chris@0 810 copied_issue = @project.issues.first(:conditions => {:subject => "change the new issues to use the copied version"})
Chris@0 811
Chris@0 812 assert copied_issue
Chris@0 813 assert copied_issue.fixed_version
Chris@0 814 assert_equal "Assigned Issues", copied_issue.fixed_version.name # Same name
Chris@0 815 assert_not_equal assigned_version.id, copied_issue.fixed_version.id # Different record
Chris@0 816 end
Chris@0 817
Chris@0 818 should "copy issue relations" do
Chris@0 819 Setting.cross_project_issue_relations = '1'
Chris@0 820
Chris@0 821 second_issue = Issue.generate!(:status_id => 5,
Chris@0 822 :subject => "copy issue relation",
Chris@0 823 :tracker_id => 1,
Chris@0 824 :assigned_to_id => 2,
Chris@0 825 :project_id => @source_project.id)
Chris@0 826 source_relation = IssueRelation.generate!(:issue_from => Issue.find(4),
Chris@0 827 :issue_to => second_issue,
Chris@0 828 :relation_type => "relates")
Chris@0 829 source_relation_cross_project = IssueRelation.generate!(:issue_from => Issue.find(1),
Chris@0 830 :issue_to => second_issue,
Chris@0 831 :relation_type => "duplicates")
Chris@0 832
Chris@0 833 assert @project.copy(@source_project)
Chris@0 834 assert_equal @source_project.issues.count, @project.issues.count
Chris@0 835 copied_issue = @project.issues.find_by_subject("Issue on project 2") # Was #4
Chris@0 836 copied_second_issue = @project.issues.find_by_subject("copy issue relation")
Chris@0 837
Chris@0 838 # First issue with a relation on project
Chris@0 839 assert_equal 1, copied_issue.relations.size, "Relation not copied"
Chris@0 840 copied_relation = copied_issue.relations.first
Chris@0 841 assert_equal "relates", copied_relation.relation_type
Chris@0 842 assert_equal copied_second_issue.id, copied_relation.issue_to_id
Chris@0 843 assert_not_equal source_relation.id, copied_relation.id
Chris@0 844
Chris@0 845 # Second issue with a cross project relation
Chris@0 846 assert_equal 2, copied_second_issue.relations.size, "Relation not copied"
Chris@0 847 copied_relation = copied_second_issue.relations.select {|r| r.relation_type == 'duplicates'}.first
Chris@0 848 assert_equal "duplicates", copied_relation.relation_type
Chris@0 849 assert_equal 1, copied_relation.issue_from_id, "Cross project relation not kept"
Chris@0 850 assert_not_equal source_relation_cross_project.id, copied_relation.id
Chris@0 851 end
Chris@0 852
Chris@0 853 should "copy memberships" do
Chris@0 854 assert @project.valid?
Chris@0 855 assert @project.members.empty?
Chris@0 856 assert @project.copy(@source_project)
Chris@0 857
Chris@0 858 assert_equal @source_project.memberships.size, @project.memberships.size
Chris@0 859 @project.memberships.each do |membership|
Chris@0 860 assert membership
Chris@0 861 assert_equal @project, membership.project
Chris@0 862 end
Chris@0 863 end
Chris@119 864
Chris@119 865 should "copy memberships with groups and additional roles" do
Chris@119 866 group = Group.create!(:lastname => "Copy group")
Chris@119 867 user = User.find(7)
Chris@119 868 group.users << user
Chris@119 869 # group role
Chris@119 870 Member.create!(:project_id => @source_project.id, :principal => group, :role_ids => [2])
Chris@119 871 member = Member.find_by_user_id_and_project_id(user.id, @source_project.id)
Chris@119 872 # additional role
Chris@119 873 member.role_ids = [1]
Chris@119 874
Chris@119 875 assert @project.copy(@source_project)
Chris@119 876 member = Member.find_by_user_id_and_project_id(user.id, @project.id)
Chris@119 877 assert_not_nil member
Chris@119 878 assert_equal [1, 2], member.role_ids.sort
Chris@119 879 end
Chris@0 880
Chris@0 881 should "copy project specific queries" do
Chris@0 882 assert @project.valid?
Chris@0 883 assert @project.queries.empty?
Chris@0 884 assert @project.copy(@source_project)
Chris@0 885
Chris@0 886 assert_equal @source_project.queries.size, @project.queries.size
Chris@0 887 @project.queries.each do |query|
Chris@0 888 assert query
Chris@0 889 assert_equal @project, query.project
Chris@0 890 end
Chris@0 891 end
Chris@0 892
Chris@0 893 should "copy versions" do
Chris@0 894 @source_project.versions << Version.generate!
Chris@0 895 @source_project.versions << Version.generate!
Chris@0 896
Chris@0 897 assert @project.versions.empty?
Chris@0 898 assert @project.copy(@source_project)
Chris@0 899
Chris@0 900 assert_equal @source_project.versions.size, @project.versions.size
Chris@0 901 @project.versions.each do |version|
Chris@0 902 assert version
Chris@0 903 assert_equal @project, version.project
Chris@0 904 end
Chris@0 905 end
Chris@0 906
Chris@0 907 should "copy wiki" do
Chris@0 908 assert_difference 'Wiki.count' do
Chris@0 909 assert @project.copy(@source_project)
Chris@0 910 end
Chris@0 911
Chris@0 912 assert @project.wiki
Chris@0 913 assert_not_equal @source_project.wiki, @project.wiki
Chris@0 914 assert_equal "Start page", @project.wiki.start_page
Chris@0 915 end
Chris@0 916
Chris@0 917 should "copy wiki pages and content with hierarchy" do
Chris@0 918 assert_difference 'WikiPage.count', @source_project.wiki.pages.size do
Chris@0 919 assert @project.copy(@source_project)
Chris@0 920 end
Chris@0 921
Chris@0 922 assert @project.wiki
Chris@0 923 assert_equal @source_project.wiki.pages.size, @project.wiki.pages.size
Chris@0 924
Chris@0 925 @project.wiki.pages.each do |wiki_page|
Chris@0 926 assert wiki_page.content
Chris@0 927 assert !@source_project.wiki.pages.include?(wiki_page)
Chris@0 928 end
Chris@0 929
Chris@0 930 parent = @project.wiki.find_page('Parent_page')
Chris@0 931 child1 = @project.wiki.find_page('Child_page_1')
Chris@0 932 child2 = @project.wiki.find_page('Child_page_2')
Chris@0 933 assert_equal parent, child1.parent
Chris@0 934 assert_equal parent, child2.parent
Chris@0 935 end
Chris@0 936
Chris@0 937 should "copy issue categories" do
Chris@0 938 assert @project.copy(@source_project)
Chris@0 939
Chris@0 940 assert_equal 2, @project.issue_categories.size
Chris@0 941 @project.issue_categories.each do |issue_category|
Chris@0 942 assert !@source_project.issue_categories.include?(issue_category)
Chris@0 943 end
Chris@0 944 end
Chris@0 945
Chris@0 946 should "copy boards" do
Chris@0 947 assert @project.copy(@source_project)
Chris@0 948
Chris@0 949 assert_equal 1, @project.boards.size
Chris@0 950 @project.boards.each do |board|
Chris@0 951 assert !@source_project.boards.include?(board)
Chris@0 952 end
Chris@0 953 end
Chris@0 954
Chris@0 955 should "change the new issues to use the copied issue categories" do
Chris@0 956 issue = Issue.find(4)
Chris@0 957 issue.update_attribute(:category_id, 3)
Chris@0 958
Chris@0 959 assert @project.copy(@source_project)
Chris@0 960
Chris@0 961 @project.issues.each do |issue|
Chris@0 962 assert issue.category
Chris@0 963 assert_equal "Stock management", issue.category.name # Same name
Chris@0 964 assert_not_equal IssueCategory.find(3), issue.category # Different record
Chris@0 965 end
Chris@0 966 end
Chris@0 967
Chris@0 968 should "limit copy with :only option" do
Chris@0 969 assert @project.members.empty?
Chris@0 970 assert @project.issue_categories.empty?
Chris@0 971 assert @source_project.issues.any?
Chris@0 972
Chris@0 973 assert @project.copy(@source_project, :only => ['members', 'issue_categories'])
Chris@0 974
Chris@0 975 assert @project.members.any?
Chris@0 976 assert @project.issue_categories.any?
Chris@0 977 assert @project.issues.empty?
Chris@0 978 end
Chris@0 979
Chris@0 980 end
Chris@0 981
chris@22 982 context "#start_date" do
chris@22 983 setup do
chris@22 984 ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests
chris@22 985 @project = Project.generate!(:identifier => 'test0')
chris@22 986 @project.trackers << Tracker.generate!
chris@22 987 end
chris@22 988
chris@22 989 should "be nil if there are no issues on the project" do
chris@22 990 assert_nil @project.start_date
chris@22 991 end
chris@37 992
chris@37 993 should "be tested when issues have no start date"
chris@22 994
chris@22 995 should "be the earliest start date of it's issues" do
chris@22 996 early = 7.days.ago.to_date
chris@22 997 Issue.generate_for_project!(@project, :start_date => Date.today)
chris@22 998 Issue.generate_for_project!(@project, :start_date => early)
chris@22 999
chris@22 1000 assert_equal early, @project.start_date
chris@22 1001 end
chris@22 1002
chris@22 1003 end
chris@22 1004
chris@22 1005 context "#due_date" do
chris@22 1006 setup do
chris@22 1007 ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests
chris@22 1008 @project = Project.generate!(:identifier => 'test0')
chris@22 1009 @project.trackers << Tracker.generate!
chris@22 1010 end
chris@22 1011
chris@22 1012 should "be nil if there are no issues on the project" do
chris@22 1013 assert_nil @project.due_date
chris@22 1014 end
chris@37 1015
chris@37 1016 should "be tested when issues have no due date"
chris@22 1017
chris@22 1018 should "be the latest due date of it's issues" do
chris@22 1019 future = 7.days.from_now.to_date
chris@22 1020 Issue.generate_for_project!(@project, :due_date => future)
chris@22 1021 Issue.generate_for_project!(@project, :due_date => Date.today)
chris@22 1022
chris@22 1023 assert_equal future, @project.due_date
chris@22 1024 end
chris@22 1025
chris@22 1026 should "be the latest due date of it's versions" do
chris@22 1027 future = 7.days.from_now.to_date
chris@22 1028 @project.versions << Version.generate!(:effective_date => future)
chris@22 1029 @project.versions << Version.generate!(:effective_date => Date.today)
chris@22 1030
chris@22 1031
chris@22 1032 assert_equal future, @project.due_date
chris@22 1033
chris@22 1034 end
chris@22 1035
chris@22 1036 should "pick the latest date from it's issues and versions" do
chris@22 1037 future = 7.days.from_now.to_date
chris@22 1038 far_future = 14.days.from_now.to_date
chris@22 1039 Issue.generate_for_project!(@project, :due_date => far_future)
chris@22 1040 @project.versions << Version.generate!(:effective_date => future)
chris@22 1041
chris@22 1042 assert_equal far_future, @project.due_date
chris@22 1043 end
chris@22 1044
chris@22 1045 end
chris@22 1046
chris@22 1047 context "Project#completed_percent" do
chris@22 1048 setup do
chris@22 1049 ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests
chris@22 1050 @project = Project.generate!(:identifier => 'test0')
chris@22 1051 @project.trackers << Tracker.generate!
chris@22 1052 end
chris@22 1053
chris@22 1054 context "no versions" do
chris@22 1055 should "be 100" do
chris@22 1056 assert_equal 100, @project.completed_percent
chris@22 1057 end
chris@22 1058 end
chris@22 1059
chris@22 1060 context "with versions" do
chris@22 1061 should "return 0 if the versions have no issues" do
chris@22 1062 Version.generate!(:project => @project)
chris@22 1063 Version.generate!(:project => @project)
chris@22 1064
chris@22 1065 assert_equal 0, @project.completed_percent
chris@22 1066 end
chris@22 1067
chris@22 1068 should "return 100 if the version has only closed issues" do
chris@22 1069 v1 = Version.generate!(:project => @project)
chris@22 1070 Issue.generate_for_project!(@project, :status => IssueStatus.find_by_name('Closed'), :fixed_version => v1)
chris@22 1071 v2 = Version.generate!(:project => @project)
chris@22 1072 Issue.generate_for_project!(@project, :status => IssueStatus.find_by_name('Closed'), :fixed_version => v2)
chris@22 1073
chris@22 1074 assert_equal 100, @project.completed_percent
chris@22 1075 end
chris@22 1076
chris@22 1077 should "return the averaged completed percent of the versions (not weighted)" do
chris@22 1078 v1 = Version.generate!(:project => @project)
chris@22 1079 Issue.generate_for_project!(@project, :status => IssueStatus.find_by_name('New'), :estimated_hours => 10, :done_ratio => 50, :fixed_version => v1)
chris@22 1080 v2 = Version.generate!(:project => @project)
chris@22 1081 Issue.generate_for_project!(@project, :status => IssueStatus.find_by_name('New'), :estimated_hours => 10, :done_ratio => 50, :fixed_version => v2)
chris@22 1082
chris@22 1083 assert_equal 50, @project.completed_percent
chris@22 1084 end
chris@22 1085
chris@22 1086 end
chris@22 1087 end
chris@37 1088
chris@37 1089 context "#notified_users" do
chris@37 1090 setup do
chris@37 1091 @project = Project.generate!
chris@37 1092 @role = Role.generate!
chris@37 1093
chris@37 1094 @user_with_membership_notification = User.generate!(:mail_notification => 'selected')
chris@37 1095 Member.generate!(:project => @project, :roles => [@role], :principal => @user_with_membership_notification, :mail_notification => true)
chris@37 1096
chris@37 1097 @all_events_user = User.generate!(:mail_notification => 'all')
chris@37 1098 Member.generate!(:project => @project, :roles => [@role], :principal => @all_events_user)
chris@37 1099
chris@37 1100 @no_events_user = User.generate!(:mail_notification => 'none')
chris@37 1101 Member.generate!(:project => @project, :roles => [@role], :principal => @no_events_user)
chris@37 1102
chris@37 1103 @only_my_events_user = User.generate!(:mail_notification => 'only_my_events')
chris@37 1104 Member.generate!(:project => @project, :roles => [@role], :principal => @only_my_events_user)
chris@37 1105
chris@37 1106 @only_assigned_user = User.generate!(:mail_notification => 'only_assigned')
chris@37 1107 Member.generate!(:project => @project, :roles => [@role], :principal => @only_assigned_user)
chris@37 1108
chris@37 1109 @only_owned_user = User.generate!(:mail_notification => 'only_owner')
chris@37 1110 Member.generate!(:project => @project, :roles => [@role], :principal => @only_owned_user)
chris@37 1111 end
chris@37 1112
chris@37 1113 should "include members with a mail notification" do
chris@37 1114 assert @project.notified_users.include?(@user_with_membership_notification)
chris@37 1115 end
chris@37 1116
chris@37 1117 should "include users with the 'all' notification option" do
chris@37 1118 assert @project.notified_users.include?(@all_events_user)
chris@37 1119 end
chris@37 1120
chris@37 1121 should "not include users with the 'none' notification option" do
chris@37 1122 assert !@project.notified_users.include?(@no_events_user)
chris@37 1123 end
chris@37 1124
chris@37 1125 should "not include users with the 'only_my_events' notification option" do
chris@37 1126 assert !@project.notified_users.include?(@only_my_events_user)
chris@37 1127 end
chris@37 1128
chris@37 1129 should "not include users with the 'only_assigned' notification option" do
chris@37 1130 assert !@project.notified_users.include?(@only_assigned_user)
chris@37 1131 end
chris@37 1132
chris@37 1133 should "not include users with the 'only_owner' notification option" do
chris@37 1134 assert !@project.notified_users.include?(@only_owned_user)
chris@37 1135 end
chris@37 1136 end
chris@37 1137
Chris@0 1138 end