annotate .svn/pristine/41/41dbe19704933be68922a961147886290a8f9c62.svn-base @ 929:5f33065ddc4b redmine-1.3

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