annotate test/unit/project_test.rb @ 904:0a8317a50fa0 redmine-1.1

Close obsolete branch redmine-1.1
author Chris Cannam
date Fri, 14 Jan 2011 12:53:21 +0000
parents af80e5618e9b
children cbce1fd3b1b7
rev   line source
Chris@0 1 # redMine - project management software
Chris@0 2 # Copyright (C) 2006-2007 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@117 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@117 63 def test_default_attributes
Chris@117 64 with_settings :default_projects_public => '1' do
Chris@117 65 assert_equal true, Project.new.is_public
Chris@117 66 assert_equal false, Project.new(:is_public => false).is_public
Chris@117 67 end
Chris@117 68
Chris@117 69 with_settings :default_projects_public => '0' do
Chris@117 70 assert_equal false, Project.new.is_public
Chris@117 71 assert_equal true, Project.new(:is_public => true).is_public
Chris@117 72 end
Chris@117 73
Chris@117 74 with_settings :sequential_project_identifiers => '1' do
Chris@117 75 assert !Project.new.identifier.blank?
Chris@117 76 assert Project.new(:identifier => '').identifier.blank?
Chris@117 77 end
Chris@117 78
Chris@117 79 with_settings :sequential_project_identifiers => '0' do
Chris@117 80 assert Project.new.identifier.blank?
Chris@117 81 assert !Project.new(:identifier => 'test').blank?
Chris@117 82 end
Chris@117 83
Chris@117 84 with_settings :default_projects_modules => ['issue_tracking', 'repository'] do
Chris@117 85 assert_equal ['issue_tracking', 'repository'], Project.new.enabled_module_names
Chris@117 86 end
Chris@117 87
Chris@117 88 assert_equal Tracker.all, Project.new.trackers
Chris@117 89 assert_equal Tracker.find(1, 3), Project.new(:tracker_ids => [1, 3]).trackers
Chris@117 90 end
Chris@117 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@0 185 def test_move_an_orphan_project_to_a_root_project
Chris@0 186 sub = Project.find(2)
Chris@0 187 sub.set_parent! @ecookbook
Chris@0 188 assert_equal @ecookbook.id, sub.parent.id
Chris@0 189 @ecookbook.reload
Chris@0 190 assert_equal 4, @ecookbook.children.size
Chris@0 191 end
Chris@0 192
Chris@0 193 def test_move_an_orphan_project_to_a_subproject
Chris@0 194 sub = Project.find(2)
Chris@0 195 assert sub.set_parent!(@ecookbook_sub1)
Chris@0 196 end
Chris@0 197
Chris@0 198 def test_move_a_root_project_to_a_project
Chris@0 199 sub = @ecookbook
Chris@0 200 assert sub.set_parent!(Project.find(2))
Chris@0 201 end
Chris@0 202
Chris@0 203 def test_should_not_move_a_project_to_its_children
Chris@0 204 sub = @ecookbook
Chris@0 205 assert !(sub.set_parent!(Project.find(3)))
Chris@0 206 end
Chris@0 207
Chris@0 208 def test_set_parent_should_add_roots_in_alphabetical_order
Chris@0 209 ProjectCustomField.delete_all
Chris@0 210 Project.delete_all
Chris@0 211 Project.create!(:name => 'Project C', :identifier => 'project-c').set_parent!(nil)
Chris@0 212 Project.create!(:name => 'Project B', :identifier => 'project-b').set_parent!(nil)
Chris@0 213 Project.create!(:name => 'Project D', :identifier => 'project-d').set_parent!(nil)
Chris@0 214 Project.create!(:name => 'Project A', :identifier => 'project-a').set_parent!(nil)
Chris@0 215
Chris@0 216 assert_equal 4, Project.count
Chris@0 217 assert_equal Project.all.sort_by(&:name), Project.all.sort_by(&:lft)
Chris@0 218 end
Chris@0 219
Chris@0 220 def test_set_parent_should_add_children_in_alphabetical_order
Chris@0 221 ProjectCustomField.delete_all
Chris@0 222 parent = Project.create!(:name => 'Parent', :identifier => 'parent')
Chris@0 223 Project.create!(:name => 'Project C', :identifier => 'project-c').set_parent!(parent)
Chris@0 224 Project.create!(:name => 'Project B', :identifier => 'project-b').set_parent!(parent)
Chris@0 225 Project.create!(:name => 'Project D', :identifier => 'project-d').set_parent!(parent)
Chris@0 226 Project.create!(:name => 'Project A', :identifier => 'project-a').set_parent!(parent)
Chris@0 227
Chris@0 228 parent.reload
Chris@0 229 assert_equal 4, parent.children.size
Chris@0 230 assert_equal parent.children.sort_by(&:name), parent.children
Chris@0 231 end
Chris@0 232
Chris@0 233 def test_rebuild_should_sort_children_alphabetically
Chris@0 234 ProjectCustomField.delete_all
Chris@0 235 parent = Project.create!(:name => 'Parent', :identifier => 'parent')
Chris@0 236 Project.create!(:name => 'Project C', :identifier => 'project-c').move_to_child_of(parent)
Chris@0 237 Project.create!(:name => 'Project B', :identifier => 'project-b').move_to_child_of(parent)
Chris@0 238 Project.create!(:name => 'Project D', :identifier => 'project-d').move_to_child_of(parent)
Chris@0 239 Project.create!(:name => 'Project A', :identifier => 'project-a').move_to_child_of(parent)
Chris@0 240
Chris@0 241 Project.update_all("lft = NULL, rgt = NULL")
Chris@0 242 Project.rebuild!
Chris@0 243
Chris@0 244 parent.reload
Chris@0 245 assert_equal 4, parent.children.size
Chris@0 246 assert_equal parent.children.sort_by(&:name), parent.children
Chris@0 247 end
Chris@0 248
Chris@0 249
Chris@0 250 def test_set_parent_should_update_issue_fixed_version_associations_when_a_fixed_version_is_moved_out_of_the_hierarchy
Chris@0 251 # Parent issue with a hierarchy project's fixed version
Chris@0 252 parent_issue = Issue.find(1)
Chris@0 253 parent_issue.update_attribute(:fixed_version_id, 4)
Chris@0 254 parent_issue.reload
Chris@0 255 assert_equal 4, parent_issue.fixed_version_id
Chris@0 256
Chris@0 257 # Should keep fixed versions for the issues
Chris@0 258 issue_with_local_fixed_version = Issue.find(5)
Chris@0 259 issue_with_local_fixed_version.update_attribute(:fixed_version_id, 4)
Chris@0 260 issue_with_local_fixed_version.reload
Chris@0 261 assert_equal 4, issue_with_local_fixed_version.fixed_version_id
Chris@0 262
Chris@0 263 # Local issue with hierarchy fixed_version
Chris@0 264 issue_with_hierarchy_fixed_version = Issue.find(13)
Chris@0 265 issue_with_hierarchy_fixed_version.update_attribute(:fixed_version_id, 6)
Chris@0 266 issue_with_hierarchy_fixed_version.reload
Chris@0 267 assert_equal 6, issue_with_hierarchy_fixed_version.fixed_version_id
Chris@0 268
Chris@0 269 # Move project out of the issue's hierarchy
Chris@0 270 moved_project = Project.find(3)
Chris@0 271 moved_project.set_parent!(Project.find(2))
Chris@0 272 parent_issue.reload
Chris@0 273 issue_with_local_fixed_version.reload
Chris@0 274 issue_with_hierarchy_fixed_version.reload
Chris@0 275
Chris@0 276 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 277 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 278 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 279 end
Chris@0 280
Chris@0 281 def test_parent
Chris@0 282 p = Project.find(6).parent
Chris@0 283 assert p.is_a?(Project)
Chris@0 284 assert_equal 5, p.id
Chris@0 285 end
Chris@0 286
Chris@0 287 def test_ancestors
Chris@0 288 a = Project.find(6).ancestors
Chris@0 289 assert a.first.is_a?(Project)
Chris@0 290 assert_equal [1, 5], a.collect(&:id)
Chris@0 291 end
Chris@0 292
Chris@0 293 def test_root
Chris@0 294 r = Project.find(6).root
Chris@0 295 assert r.is_a?(Project)
Chris@0 296 assert_equal 1, r.id
Chris@0 297 end
Chris@0 298
Chris@0 299 def test_children
Chris@0 300 c = Project.find(1).children
Chris@0 301 assert c.first.is_a?(Project)
Chris@0 302 assert_equal [5, 3, 4], c.collect(&:id)
Chris@0 303 end
Chris@0 304
Chris@0 305 def test_descendants
Chris@0 306 d = Project.find(1).descendants
Chris@0 307 assert d.first.is_a?(Project)
Chris@0 308 assert_equal [5, 6, 3, 4], d.collect(&:id)
Chris@0 309 end
Chris@0 310
Chris@0 311 def test_allowed_parents_should_be_empty_for_non_member_user
Chris@0 312 Role.non_member.add_permission!(:add_project)
Chris@0 313 user = User.find(9)
Chris@0 314 assert user.memberships.empty?
Chris@0 315 User.current = user
Chris@0 316 assert Project.new.allowed_parents.compact.empty?
Chris@0 317 end
Chris@0 318
Chris@0 319 def test_allowed_parents_with_add_subprojects_permission
Chris@0 320 Role.find(1).remove_permission!(:add_project)
Chris@0 321 Role.find(1).add_permission!(:add_subprojects)
Chris@0 322 User.current = User.find(2)
Chris@0 323 # new project
Chris@0 324 assert !Project.new.allowed_parents.include?(nil)
Chris@0 325 assert Project.new.allowed_parents.include?(Project.find(1))
Chris@0 326 # existing root project
Chris@0 327 assert Project.find(1).allowed_parents.include?(nil)
Chris@0 328 # existing child
Chris@0 329 assert Project.find(3).allowed_parents.include?(Project.find(1))
Chris@0 330 assert !Project.find(3).allowed_parents.include?(nil)
Chris@0 331 end
Chris@0 332
Chris@0 333 def test_allowed_parents_with_add_project_permission
Chris@0 334 Role.find(1).add_permission!(:add_project)
Chris@0 335 Role.find(1).remove_permission!(:add_subprojects)
Chris@0 336 User.current = User.find(2)
Chris@0 337 # new project
Chris@0 338 assert Project.new.allowed_parents.include?(nil)
Chris@0 339 assert !Project.new.allowed_parents.include?(Project.find(1))
Chris@0 340 # existing root project
Chris@0 341 assert Project.find(1).allowed_parents.include?(nil)
Chris@0 342 # existing child
Chris@0 343 assert Project.find(3).allowed_parents.include?(Project.find(1))
Chris@0 344 assert Project.find(3).allowed_parents.include?(nil)
Chris@0 345 end
Chris@0 346
Chris@0 347 def test_allowed_parents_with_add_project_and_subprojects_permission
Chris@0 348 Role.find(1).add_permission!(:add_project)
Chris@0 349 Role.find(1).add_permission!(:add_subprojects)
Chris@0 350 User.current = User.find(2)
Chris@0 351 # new project
Chris@0 352 assert Project.new.allowed_parents.include?(nil)
Chris@0 353 assert Project.new.allowed_parents.include?(Project.find(1))
Chris@0 354 # existing root project
Chris@0 355 assert Project.find(1).allowed_parents.include?(nil)
Chris@0 356 # existing child
Chris@0 357 assert Project.find(3).allowed_parents.include?(Project.find(1))
Chris@0 358 assert Project.find(3).allowed_parents.include?(nil)
Chris@0 359 end
Chris@0 360
Chris@0 361 def test_users_by_role
Chris@0 362 users_by_role = Project.find(1).users_by_role
Chris@0 363 assert_kind_of Hash, users_by_role
Chris@0 364 role = Role.find(1)
Chris@0 365 assert_kind_of Array, users_by_role[role]
Chris@0 366 assert users_by_role[role].include?(User.find(2))
Chris@0 367 end
Chris@0 368
Chris@0 369 def test_rolled_up_trackers
Chris@0 370 parent = Project.find(1)
Chris@0 371 parent.trackers = Tracker.find([1,2])
Chris@0 372 child = parent.children.find(3)
Chris@0 373
Chris@0 374 assert_equal [1, 2], parent.tracker_ids
Chris@0 375 assert_equal [2, 3], child.trackers.collect(&:id)
Chris@0 376
Chris@0 377 assert_kind_of Tracker, parent.rolled_up_trackers.first
Chris@0 378 assert_equal Tracker.find(1), parent.rolled_up_trackers.first
Chris@0 379
Chris@0 380 assert_equal [1, 2, 3], parent.rolled_up_trackers.collect(&:id)
Chris@0 381 assert_equal [2, 3], child.rolled_up_trackers.collect(&:id)
Chris@0 382 end
Chris@0 383
Chris@0 384 def test_rolled_up_trackers_should_ignore_archived_subprojects
Chris@0 385 parent = Project.find(1)
Chris@0 386 parent.trackers = Tracker.find([1,2])
Chris@0 387 child = parent.children.find(3)
Chris@0 388 child.trackers = Tracker.find([1,3])
Chris@0 389 parent.children.each(&:archive)
Chris@0 390
Chris@0 391 assert_equal [1,2], parent.rolled_up_trackers.collect(&:id)
Chris@0 392 end
Chris@0 393
Chris@0 394 context "#rolled_up_versions" do
Chris@0 395 setup do
Chris@0 396 @project = Project.generate!
Chris@0 397 @parent_version_1 = Version.generate!(:project => @project)
Chris@0 398 @parent_version_2 = Version.generate!(:project => @project)
Chris@0 399 end
Chris@0 400
Chris@0 401 should "include the versions for the current project" do
Chris@0 402 assert_same_elements [@parent_version_1, @parent_version_2], @project.rolled_up_versions
Chris@0 403 end
Chris@0 404
Chris@0 405 should "include versions for a subproject" do
Chris@0 406 @subproject = Project.generate!
Chris@0 407 @subproject.set_parent!(@project)
Chris@0 408 @subproject_version = Version.generate!(:project => @subproject)
Chris@0 409
Chris@0 410 assert_same_elements [
Chris@0 411 @parent_version_1,
Chris@0 412 @parent_version_2,
Chris@0 413 @subproject_version
Chris@0 414 ], @project.rolled_up_versions
Chris@0 415 end
Chris@0 416
Chris@0 417 should "include versions for a sub-subproject" do
Chris@0 418 @subproject = Project.generate!
Chris@0 419 @subproject.set_parent!(@project)
Chris@0 420 @sub_subproject = Project.generate!
Chris@0 421 @sub_subproject.set_parent!(@subproject)
Chris@0 422 @sub_subproject_version = Version.generate!(:project => @sub_subproject)
Chris@0 423
Chris@0 424 @project.reload
Chris@0 425
Chris@0 426 assert_same_elements [
Chris@0 427 @parent_version_1,
Chris@0 428 @parent_version_2,
Chris@0 429 @sub_subproject_version
Chris@0 430 ], @project.rolled_up_versions
Chris@0 431 end
Chris@0 432
Chris@0 433
Chris@0 434 should "only check active projects" do
Chris@0 435 @subproject = Project.generate!
Chris@0 436 @subproject.set_parent!(@project)
Chris@0 437 @subproject_version = Version.generate!(:project => @subproject)
Chris@0 438 assert @subproject.archive
Chris@0 439
Chris@0 440 @project.reload
Chris@0 441
Chris@0 442 assert !@subproject.active?
Chris@0 443 assert_same_elements [@parent_version_1, @parent_version_2], @project.rolled_up_versions
Chris@0 444 end
Chris@0 445 end
Chris@0 446
Chris@0 447 def test_shared_versions_none_sharing
Chris@0 448 p = Project.find(5)
Chris@0 449 v = Version.create!(:name => 'none_sharing', :project => p, :sharing => 'none')
Chris@0 450 assert p.shared_versions.include?(v)
Chris@0 451 assert !p.children.first.shared_versions.include?(v)
Chris@0 452 assert !p.root.shared_versions.include?(v)
Chris@0 453 assert !p.siblings.first.shared_versions.include?(v)
Chris@0 454 assert !p.root.siblings.first.shared_versions.include?(v)
Chris@0 455 end
Chris@0 456
Chris@0 457 def test_shared_versions_descendants_sharing
Chris@0 458 p = Project.find(5)
Chris@0 459 v = Version.create!(:name => 'descendants_sharing', :project => p, :sharing => 'descendants')
Chris@0 460 assert p.shared_versions.include?(v)
Chris@0 461 assert p.children.first.shared_versions.include?(v)
Chris@0 462 assert !p.root.shared_versions.include?(v)
Chris@0 463 assert !p.siblings.first.shared_versions.include?(v)
Chris@0 464 assert !p.root.siblings.first.shared_versions.include?(v)
Chris@0 465 end
Chris@0 466
Chris@0 467 def test_shared_versions_hierarchy_sharing
Chris@0 468 p = Project.find(5)
Chris@0 469 v = Version.create!(:name => 'hierarchy_sharing', :project => p, :sharing => 'hierarchy')
Chris@0 470 assert p.shared_versions.include?(v)
Chris@0 471 assert p.children.first.shared_versions.include?(v)
Chris@0 472 assert p.root.shared_versions.include?(v)
Chris@0 473 assert !p.siblings.first.shared_versions.include?(v)
Chris@0 474 assert !p.root.siblings.first.shared_versions.include?(v)
Chris@0 475 end
Chris@0 476
Chris@0 477 def test_shared_versions_tree_sharing
Chris@0 478 p = Project.find(5)
Chris@0 479 v = Version.create!(:name => 'tree_sharing', :project => p, :sharing => 'tree')
Chris@0 480 assert p.shared_versions.include?(v)
Chris@0 481 assert p.children.first.shared_versions.include?(v)
Chris@0 482 assert p.root.shared_versions.include?(v)
Chris@0 483 assert p.siblings.first.shared_versions.include?(v)
Chris@0 484 assert !p.root.siblings.first.shared_versions.include?(v)
Chris@0 485 end
Chris@0 486
Chris@0 487 def test_shared_versions_system_sharing
Chris@0 488 p = Project.find(5)
Chris@0 489 v = Version.create!(:name => 'system_sharing', :project => p, :sharing => 'system')
Chris@0 490 assert p.shared_versions.include?(v)
Chris@0 491 assert p.children.first.shared_versions.include?(v)
Chris@0 492 assert p.root.shared_versions.include?(v)
Chris@0 493 assert p.siblings.first.shared_versions.include?(v)
Chris@0 494 assert p.root.siblings.first.shared_versions.include?(v)
Chris@0 495 end
Chris@0 496
Chris@0 497 def test_shared_versions
Chris@0 498 parent = Project.find(1)
Chris@0 499 child = parent.children.find(3)
Chris@0 500 private_child = parent.children.find(5)
Chris@0 501
Chris@0 502 assert_equal [1,2,3], parent.version_ids.sort
Chris@0 503 assert_equal [4], child.version_ids
Chris@0 504 assert_equal [6], private_child.version_ids
Chris@0 505 assert_equal [7], Version.find_all_by_sharing('system').collect(&:id)
Chris@0 506
Chris@0 507 assert_equal 6, parent.shared_versions.size
Chris@0 508 parent.shared_versions.each do |version|
Chris@0 509 assert_kind_of Version, version
Chris@0 510 end
Chris@0 511
Chris@0 512 assert_equal [1,2,3,4,6,7], parent.shared_versions.collect(&:id).sort
Chris@0 513 end
Chris@0 514
Chris@0 515 def test_shared_versions_should_ignore_archived_subprojects
Chris@0 516 parent = Project.find(1)
Chris@0 517 child = parent.children.find(3)
Chris@0 518 child.archive
Chris@0 519 parent.reload
Chris@0 520
Chris@0 521 assert_equal [1,2,3], parent.version_ids.sort
Chris@0 522 assert_equal [4], child.version_ids
Chris@0 523 assert !parent.shared_versions.collect(&:id).include?(4)
Chris@0 524 end
Chris@0 525
Chris@0 526 def test_shared_versions_visible_to_user
Chris@0 527 user = User.find(3)
Chris@0 528 parent = Project.find(1)
Chris@0 529 child = parent.children.find(5)
Chris@0 530
Chris@0 531 assert_equal [1,2,3], parent.version_ids.sort
Chris@0 532 assert_equal [6], child.version_ids
Chris@0 533
Chris@0 534 versions = parent.shared_versions.visible(user)
Chris@0 535
Chris@0 536 assert_equal 4, versions.size
Chris@0 537 versions.each do |version|
Chris@0 538 assert_kind_of Version, version
Chris@0 539 end
Chris@0 540
Chris@0 541 assert !versions.collect(&:id).include?(6)
Chris@0 542 end
Chris@0 543
Chris@0 544
Chris@0 545 def test_next_identifier
Chris@0 546 ProjectCustomField.delete_all
Chris@0 547 Project.create!(:name => 'last', :identifier => 'p2008040')
Chris@0 548 assert_equal 'p2008041', Project.next_identifier
Chris@0 549 end
Chris@0 550
Chris@0 551 def test_next_identifier_first_project
Chris@0 552 Project.delete_all
Chris@0 553 assert_nil Project.next_identifier
Chris@0 554 end
Chris@0 555
Chris@0 556
Chris@0 557 def test_enabled_module_names_should_not_recreate_enabled_modules
Chris@0 558 project = Project.find(1)
Chris@0 559 # Remove one module
Chris@0 560 modules = project.enabled_modules.slice(0..-2)
Chris@0 561 assert modules.any?
Chris@0 562 assert_difference 'EnabledModule.count', -1 do
Chris@0 563 project.enabled_module_names = modules.collect(&:name)
Chris@0 564 end
Chris@0 565 project.reload
Chris@0 566 # Ids should be preserved
Chris@0 567 assert_equal project.enabled_module_ids.sort, modules.collect(&:id).sort
Chris@0 568 end
Chris@0 569
Chris@0 570 def test_copy_from_existing_project
Chris@0 571 source_project = Project.find(1)
Chris@0 572 copied_project = Project.copy_from(1)
Chris@0 573
Chris@0 574 assert copied_project
Chris@0 575 # Cleared attributes
Chris@0 576 assert copied_project.id.blank?
Chris@0 577 assert copied_project.name.blank?
Chris@0 578 assert copied_project.identifier.blank?
Chris@0 579
Chris@0 580 # Duplicated attributes
Chris@0 581 assert_equal source_project.description, copied_project.description
Chris@0 582 assert_equal source_project.enabled_modules, copied_project.enabled_modules
Chris@0 583 assert_equal source_project.trackers, copied_project.trackers
Chris@0 584
Chris@0 585 # Default attributes
Chris@0 586 assert_equal 1, copied_project.status
Chris@0 587 end
Chris@0 588
Chris@0 589 def test_activities_should_use_the_system_activities
Chris@0 590 project = Project.find(1)
Chris@0 591 assert_equal project.activities, TimeEntryActivity.find(:all, :conditions => {:active => true} )
Chris@0 592 end
Chris@0 593
Chris@0 594
Chris@0 595 def test_activities_should_use_the_project_specific_activities
Chris@0 596 project = Project.find(1)
Chris@0 597 overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project})
Chris@0 598 assert overridden_activity.save!
Chris@0 599
Chris@0 600 assert project.activities.include?(overridden_activity), "Project specific Activity not found"
Chris@0 601 end
Chris@0 602
Chris@0 603 def test_activities_should_not_include_the_inactive_project_specific_activities
Chris@0 604 project = Project.find(1)
Chris@0 605 overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => TimeEntryActivity.find(:first), :active => false})
Chris@0 606 assert overridden_activity.save!
Chris@0 607
Chris@0 608 assert !project.activities.include?(overridden_activity), "Inactive Project specific Activity found"
Chris@0 609 end
Chris@0 610
Chris@0 611 def test_activities_should_not_include_project_specific_activities_from_other_projects
Chris@0 612 project = Project.find(1)
Chris@0 613 overridden_activity = TimeEntryActivity.new({:name => "Project", :project => Project.find(2)})
Chris@0 614 assert overridden_activity.save!
Chris@0 615
Chris@0 616 assert !project.activities.include?(overridden_activity), "Project specific Activity found on a different project"
Chris@0 617 end
Chris@0 618
Chris@0 619 def test_activities_should_handle_nils
Chris@0 620 overridden_activity = TimeEntryActivity.new({:name => "Project", :project => Project.find(1), :parent => TimeEntryActivity.find(:first)})
Chris@0 621 TimeEntryActivity.delete_all
Chris@0 622
Chris@0 623 # No activities
Chris@0 624 project = Project.find(1)
Chris@0 625 assert project.activities.empty?
Chris@0 626
Chris@0 627 # No system, one overridden
Chris@0 628 assert overridden_activity.save!
Chris@0 629 project.reload
Chris@0 630 assert_equal [overridden_activity], project.activities
Chris@0 631 end
Chris@0 632
Chris@0 633 def test_activities_should_override_system_activities_with_project_activities
Chris@0 634 project = Project.find(1)
Chris@0 635 parent_activity = TimeEntryActivity.find(:first)
Chris@0 636 overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => parent_activity})
Chris@0 637 assert overridden_activity.save!
Chris@0 638
Chris@0 639 assert project.activities.include?(overridden_activity), "Project specific Activity not found"
Chris@0 640 assert !project.activities.include?(parent_activity), "System Activity found when it should have been overridden"
Chris@0 641 end
Chris@0 642
Chris@0 643 def test_activities_should_include_inactive_activities_if_specified
Chris@0 644 project = Project.find(1)
Chris@0 645 overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => TimeEntryActivity.find(:first), :active => false})
Chris@0 646 assert overridden_activity.save!
Chris@0 647
Chris@0 648 assert project.activities(true).include?(overridden_activity), "Inactive Project specific Activity not found"
Chris@0 649 end
Chris@0 650
Chris@0 651 test 'activities should not include active System activities if the project has an override that is inactive' do
Chris@0 652 project = Project.find(1)
Chris@0 653 system_activity = TimeEntryActivity.find_by_name('Design')
Chris@0 654 assert system_activity.active?
Chris@0 655 overridden_activity = TimeEntryActivity.generate!(:project => project, :parent => system_activity, :active => false)
Chris@0 656 assert overridden_activity.save!
Chris@0 657
Chris@0 658 assert !project.activities.include?(overridden_activity), "Inactive Project specific Activity not found"
Chris@0 659 assert !project.activities.include?(system_activity), "System activity found when the project has an inactive override"
Chris@0 660 end
Chris@0 661
Chris@0 662 def test_close_completed_versions
Chris@0 663 Version.update_all("status = 'open'")
Chris@0 664 project = Project.find(1)
Chris@0 665 assert_not_nil project.versions.detect {|v| v.completed? && v.status == 'open'}
Chris@0 666 assert_not_nil project.versions.detect {|v| !v.completed? && v.status == 'open'}
Chris@0 667 project.close_completed_versions
Chris@0 668 project.reload
Chris@0 669 assert_nil project.versions.detect {|v| v.completed? && v.status != 'closed'}
Chris@0 670 assert_not_nil project.versions.detect {|v| !v.completed? && v.status == 'open'}
Chris@0 671 end
Chris@0 672
Chris@0 673 context "Project#copy" do
Chris@0 674 setup do
Chris@0 675 ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests
Chris@0 676 Project.destroy_all :identifier => "copy-test"
Chris@0 677 @source_project = Project.find(2)
Chris@0 678 @project = Project.new(:name => 'Copy Test', :identifier => 'copy-test')
Chris@0 679 @project.trackers = @source_project.trackers
Chris@0 680 @project.enabled_module_names = @source_project.enabled_modules.collect(&:name)
Chris@0 681 end
Chris@0 682
Chris@0 683 should "copy issues" do
Chris@0 684 @source_project.issues << Issue.generate!(:status => IssueStatus.find_by_name('Closed'),
Chris@0 685 :subject => "copy issue status",
Chris@0 686 :tracker_id => 1,
Chris@0 687 :assigned_to_id => 2,
Chris@0 688 :project_id => @source_project.id)
Chris@0 689 assert @project.valid?
Chris@0 690 assert @project.issues.empty?
Chris@0 691 assert @project.copy(@source_project)
Chris@0 692
Chris@0 693 assert_equal @source_project.issues.size, @project.issues.size
Chris@0 694 @project.issues.each do |issue|
Chris@0 695 assert issue.valid?
Chris@0 696 assert ! issue.assigned_to.blank?
Chris@0 697 assert_equal @project, issue.project
Chris@0 698 end
Chris@0 699
Chris@0 700 copied_issue = @project.issues.first(:conditions => {:subject => "copy issue status"})
Chris@0 701 assert copied_issue
Chris@0 702 assert copied_issue.status
Chris@0 703 assert_equal "Closed", copied_issue.status.name
Chris@0 704 end
Chris@0 705
Chris@0 706 should "change the new issues to use the copied version" do
Chris@0 707 User.current = User.find(1)
Chris@0 708 assigned_version = Version.generate!(:name => "Assigned Issues", :status => 'open')
Chris@0 709 @source_project.versions << assigned_version
Chris@0 710 assert_equal 3, @source_project.versions.size
Chris@0 711 Issue.generate_for_project!(@source_project,
Chris@0 712 :fixed_version_id => assigned_version.id,
Chris@0 713 :subject => "change the new issues to use the copied version",
Chris@0 714 :tracker_id => 1,
Chris@0 715 :project_id => @source_project.id)
Chris@0 716
Chris@0 717 assert @project.copy(@source_project)
Chris@0 718 @project.reload
Chris@0 719 copied_issue = @project.issues.first(:conditions => {:subject => "change the new issues to use the copied version"})
Chris@0 720
Chris@0 721 assert copied_issue
Chris@0 722 assert copied_issue.fixed_version
Chris@0 723 assert_equal "Assigned Issues", copied_issue.fixed_version.name # Same name
Chris@0 724 assert_not_equal assigned_version.id, copied_issue.fixed_version.id # Different record
Chris@0 725 end
Chris@0 726
Chris@0 727 should "copy issue relations" do
Chris@0 728 Setting.cross_project_issue_relations = '1'
Chris@0 729
Chris@0 730 second_issue = Issue.generate!(:status_id => 5,
Chris@0 731 :subject => "copy issue relation",
Chris@0 732 :tracker_id => 1,
Chris@0 733 :assigned_to_id => 2,
Chris@0 734 :project_id => @source_project.id)
Chris@0 735 source_relation = IssueRelation.generate!(:issue_from => Issue.find(4),
Chris@0 736 :issue_to => second_issue,
Chris@0 737 :relation_type => "relates")
Chris@0 738 source_relation_cross_project = IssueRelation.generate!(:issue_from => Issue.find(1),
Chris@0 739 :issue_to => second_issue,
Chris@0 740 :relation_type => "duplicates")
Chris@0 741
Chris@0 742 assert @project.copy(@source_project)
Chris@0 743 assert_equal @source_project.issues.count, @project.issues.count
Chris@0 744 copied_issue = @project.issues.find_by_subject("Issue on project 2") # Was #4
Chris@0 745 copied_second_issue = @project.issues.find_by_subject("copy issue relation")
Chris@0 746
Chris@0 747 # First issue with a relation on project
Chris@0 748 assert_equal 1, copied_issue.relations.size, "Relation not copied"
Chris@0 749 copied_relation = copied_issue.relations.first
Chris@0 750 assert_equal "relates", copied_relation.relation_type
Chris@0 751 assert_equal copied_second_issue.id, copied_relation.issue_to_id
Chris@0 752 assert_not_equal source_relation.id, copied_relation.id
Chris@0 753
Chris@0 754 # Second issue with a cross project relation
Chris@0 755 assert_equal 2, copied_second_issue.relations.size, "Relation not copied"
Chris@0 756 copied_relation = copied_second_issue.relations.select {|r| r.relation_type == 'duplicates'}.first
Chris@0 757 assert_equal "duplicates", copied_relation.relation_type
Chris@0 758 assert_equal 1, copied_relation.issue_from_id, "Cross project relation not kept"
Chris@0 759 assert_not_equal source_relation_cross_project.id, copied_relation.id
Chris@0 760 end
Chris@0 761
Chris@0 762 should "copy memberships" do
Chris@0 763 assert @project.valid?
Chris@0 764 assert @project.members.empty?
Chris@0 765 assert @project.copy(@source_project)
Chris@0 766
Chris@0 767 assert_equal @source_project.memberships.size, @project.memberships.size
Chris@0 768 @project.memberships.each do |membership|
Chris@0 769 assert membership
Chris@0 770 assert_equal @project, membership.project
Chris@0 771 end
Chris@0 772 end
Chris@117 773
Chris@117 774 should "copy memberships with groups and additional roles" do
Chris@117 775 group = Group.create!(:lastname => "Copy group")
Chris@117 776 user = User.find(7)
Chris@117 777 group.users << user
Chris@117 778 # group role
Chris@117 779 Member.create!(:project_id => @source_project.id, :principal => group, :role_ids => [2])
Chris@117 780 member = Member.find_by_user_id_and_project_id(user.id, @source_project.id)
Chris@117 781 # additional role
Chris@117 782 member.role_ids = [1]
Chris@117 783
Chris@117 784 assert @project.copy(@source_project)
Chris@117 785 member = Member.find_by_user_id_and_project_id(user.id, @project.id)
Chris@117 786 assert_not_nil member
Chris@117 787 assert_equal [1, 2], member.role_ids.sort
Chris@117 788 end
Chris@0 789
Chris@0 790 should "copy project specific queries" do
Chris@0 791 assert @project.valid?
Chris@0 792 assert @project.queries.empty?
Chris@0 793 assert @project.copy(@source_project)
Chris@0 794
Chris@0 795 assert_equal @source_project.queries.size, @project.queries.size
Chris@0 796 @project.queries.each do |query|
Chris@0 797 assert query
Chris@0 798 assert_equal @project, query.project
Chris@0 799 end
Chris@0 800 end
Chris@0 801
Chris@0 802 should "copy versions" do
Chris@0 803 @source_project.versions << Version.generate!
Chris@0 804 @source_project.versions << Version.generate!
Chris@0 805
Chris@0 806 assert @project.versions.empty?
Chris@0 807 assert @project.copy(@source_project)
Chris@0 808
Chris@0 809 assert_equal @source_project.versions.size, @project.versions.size
Chris@0 810 @project.versions.each do |version|
Chris@0 811 assert version
Chris@0 812 assert_equal @project, version.project
Chris@0 813 end
Chris@0 814 end
Chris@0 815
Chris@0 816 should "copy wiki" do
Chris@0 817 assert_difference 'Wiki.count' do
Chris@0 818 assert @project.copy(@source_project)
Chris@0 819 end
Chris@0 820
Chris@0 821 assert @project.wiki
Chris@0 822 assert_not_equal @source_project.wiki, @project.wiki
Chris@0 823 assert_equal "Start page", @project.wiki.start_page
Chris@0 824 end
Chris@0 825
Chris@0 826 should "copy wiki pages and content with hierarchy" do
Chris@0 827 assert_difference 'WikiPage.count', @source_project.wiki.pages.size do
Chris@0 828 assert @project.copy(@source_project)
Chris@0 829 end
Chris@0 830
Chris@0 831 assert @project.wiki
Chris@0 832 assert_equal @source_project.wiki.pages.size, @project.wiki.pages.size
Chris@0 833
Chris@0 834 @project.wiki.pages.each do |wiki_page|
Chris@0 835 assert wiki_page.content
Chris@0 836 assert !@source_project.wiki.pages.include?(wiki_page)
Chris@0 837 end
Chris@0 838
Chris@0 839 parent = @project.wiki.find_page('Parent_page')
Chris@0 840 child1 = @project.wiki.find_page('Child_page_1')
Chris@0 841 child2 = @project.wiki.find_page('Child_page_2')
Chris@0 842 assert_equal parent, child1.parent
Chris@0 843 assert_equal parent, child2.parent
Chris@0 844 end
Chris@0 845
Chris@0 846 should "copy issue categories" do
Chris@0 847 assert @project.copy(@source_project)
Chris@0 848
Chris@0 849 assert_equal 2, @project.issue_categories.size
Chris@0 850 @project.issue_categories.each do |issue_category|
Chris@0 851 assert !@source_project.issue_categories.include?(issue_category)
Chris@0 852 end
Chris@0 853 end
Chris@0 854
Chris@0 855 should "copy boards" do
Chris@0 856 assert @project.copy(@source_project)
Chris@0 857
Chris@0 858 assert_equal 1, @project.boards.size
Chris@0 859 @project.boards.each do |board|
Chris@0 860 assert !@source_project.boards.include?(board)
Chris@0 861 end
Chris@0 862 end
Chris@0 863
Chris@0 864 should "change the new issues to use the copied issue categories" do
Chris@0 865 issue = Issue.find(4)
Chris@0 866 issue.update_attribute(:category_id, 3)
Chris@0 867
Chris@0 868 assert @project.copy(@source_project)
Chris@0 869
Chris@0 870 @project.issues.each do |issue|
Chris@0 871 assert issue.category
Chris@0 872 assert_equal "Stock management", issue.category.name # Same name
Chris@0 873 assert_not_equal IssueCategory.find(3), issue.category # Different record
Chris@0 874 end
Chris@0 875 end
Chris@0 876
Chris@0 877 should "limit copy with :only option" do
Chris@0 878 assert @project.members.empty?
Chris@0 879 assert @project.issue_categories.empty?
Chris@0 880 assert @source_project.issues.any?
Chris@0 881
Chris@0 882 assert @project.copy(@source_project, :only => ['members', 'issue_categories'])
Chris@0 883
Chris@0 884 assert @project.members.any?
Chris@0 885 assert @project.issue_categories.any?
Chris@0 886 assert @project.issues.empty?
Chris@0 887 end
Chris@0 888
Chris@0 889 end
Chris@0 890
chris@22 891 context "#start_date" do
chris@22 892 setup do
chris@22 893 ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests
chris@22 894 @project = Project.generate!(:identifier => 'test0')
chris@22 895 @project.trackers << Tracker.generate!
chris@22 896 end
chris@22 897
chris@22 898 should "be nil if there are no issues on the project" do
chris@22 899 assert_nil @project.start_date
chris@22 900 end
chris@37 901
chris@37 902 should "be tested when issues have no start date"
chris@22 903
chris@22 904 should "be the earliest start date of it's issues" do
chris@22 905 early = 7.days.ago.to_date
chris@22 906 Issue.generate_for_project!(@project, :start_date => Date.today)
chris@22 907 Issue.generate_for_project!(@project, :start_date => early)
chris@22 908
chris@22 909 assert_equal early, @project.start_date
chris@22 910 end
chris@22 911
chris@22 912 end
chris@22 913
chris@22 914 context "#due_date" do
chris@22 915 setup do
chris@22 916 ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests
chris@22 917 @project = Project.generate!(:identifier => 'test0')
chris@22 918 @project.trackers << Tracker.generate!
chris@22 919 end
chris@22 920
chris@22 921 should "be nil if there are no issues on the project" do
chris@22 922 assert_nil @project.due_date
chris@22 923 end
chris@37 924
chris@37 925 should "be tested when issues have no due date"
chris@22 926
chris@22 927 should "be the latest due date of it's issues" do
chris@22 928 future = 7.days.from_now.to_date
chris@22 929 Issue.generate_for_project!(@project, :due_date => future)
chris@22 930 Issue.generate_for_project!(@project, :due_date => Date.today)
chris@22 931
chris@22 932 assert_equal future, @project.due_date
chris@22 933 end
chris@22 934
chris@22 935 should "be the latest due date of it's versions" do
chris@22 936 future = 7.days.from_now.to_date
chris@22 937 @project.versions << Version.generate!(:effective_date => future)
chris@22 938 @project.versions << Version.generate!(:effective_date => Date.today)
chris@22 939
chris@22 940
chris@22 941 assert_equal future, @project.due_date
chris@22 942
chris@22 943 end
chris@22 944
chris@22 945 should "pick the latest date from it's issues and versions" do
chris@22 946 future = 7.days.from_now.to_date
chris@22 947 far_future = 14.days.from_now.to_date
chris@22 948 Issue.generate_for_project!(@project, :due_date => far_future)
chris@22 949 @project.versions << Version.generate!(:effective_date => future)
chris@22 950
chris@22 951 assert_equal far_future, @project.due_date
chris@22 952 end
chris@22 953
chris@22 954 end
chris@22 955
chris@22 956 context "Project#completed_percent" do
chris@22 957 setup do
chris@22 958 ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests
chris@22 959 @project = Project.generate!(:identifier => 'test0')
chris@22 960 @project.trackers << Tracker.generate!
chris@22 961 end
chris@22 962
chris@22 963 context "no versions" do
chris@22 964 should "be 100" do
chris@22 965 assert_equal 100, @project.completed_percent
chris@22 966 end
chris@22 967 end
chris@22 968
chris@22 969 context "with versions" do
chris@22 970 should "return 0 if the versions have no issues" do
chris@22 971 Version.generate!(:project => @project)
chris@22 972 Version.generate!(:project => @project)
chris@22 973
chris@22 974 assert_equal 0, @project.completed_percent
chris@22 975 end
chris@22 976
chris@22 977 should "return 100 if the version has only closed issues" do
chris@22 978 v1 = Version.generate!(:project => @project)
chris@22 979 Issue.generate_for_project!(@project, :status => IssueStatus.find_by_name('Closed'), :fixed_version => v1)
chris@22 980 v2 = Version.generate!(:project => @project)
chris@22 981 Issue.generate_for_project!(@project, :status => IssueStatus.find_by_name('Closed'), :fixed_version => v2)
chris@22 982
chris@22 983 assert_equal 100, @project.completed_percent
chris@22 984 end
chris@22 985
chris@22 986 should "return the averaged completed percent of the versions (not weighted)" do
chris@22 987 v1 = Version.generate!(:project => @project)
chris@22 988 Issue.generate_for_project!(@project, :status => IssueStatus.find_by_name('New'), :estimated_hours => 10, :done_ratio => 50, :fixed_version => v1)
chris@22 989 v2 = Version.generate!(:project => @project)
chris@22 990 Issue.generate_for_project!(@project, :status => IssueStatus.find_by_name('New'), :estimated_hours => 10, :done_ratio => 50, :fixed_version => v2)
chris@22 991
chris@22 992 assert_equal 50, @project.completed_percent
chris@22 993 end
chris@22 994
chris@22 995 end
chris@22 996 end
chris@37 997
chris@37 998 context "#notified_users" do
chris@37 999 setup do
chris@37 1000 @project = Project.generate!
chris@37 1001 @role = Role.generate!
chris@37 1002
chris@37 1003 @user_with_membership_notification = User.generate!(:mail_notification => 'selected')
chris@37 1004 Member.generate!(:project => @project, :roles => [@role], :principal => @user_with_membership_notification, :mail_notification => true)
chris@37 1005
chris@37 1006 @all_events_user = User.generate!(:mail_notification => 'all')
chris@37 1007 Member.generate!(:project => @project, :roles => [@role], :principal => @all_events_user)
chris@37 1008
chris@37 1009 @no_events_user = User.generate!(:mail_notification => 'none')
chris@37 1010 Member.generate!(:project => @project, :roles => [@role], :principal => @no_events_user)
chris@37 1011
chris@37 1012 @only_my_events_user = User.generate!(:mail_notification => 'only_my_events')
chris@37 1013 Member.generate!(:project => @project, :roles => [@role], :principal => @only_my_events_user)
chris@37 1014
chris@37 1015 @only_assigned_user = User.generate!(:mail_notification => 'only_assigned')
chris@37 1016 Member.generate!(:project => @project, :roles => [@role], :principal => @only_assigned_user)
chris@37 1017
chris@37 1018 @only_owned_user = User.generate!(:mail_notification => 'only_owner')
chris@37 1019 Member.generate!(:project => @project, :roles => [@role], :principal => @only_owned_user)
chris@37 1020 end
chris@37 1021
chris@37 1022 should "include members with a mail notification" do
chris@37 1023 assert @project.notified_users.include?(@user_with_membership_notification)
chris@37 1024 end
chris@37 1025
chris@37 1026 should "include users with the 'all' notification option" do
chris@37 1027 assert @project.notified_users.include?(@all_events_user)
chris@37 1028 end
chris@37 1029
chris@37 1030 should "not include users with the 'none' notification option" do
chris@37 1031 assert !@project.notified_users.include?(@no_events_user)
chris@37 1032 end
chris@37 1033
chris@37 1034 should "not include users with the 'only_my_events' notification option" do
chris@37 1035 assert !@project.notified_users.include?(@only_my_events_user)
chris@37 1036 end
chris@37 1037
chris@37 1038 should "not include users with the 'only_assigned' notification option" do
chris@37 1039 assert !@project.notified_users.include?(@only_assigned_user)
chris@37 1040 end
chris@37 1041
chris@37 1042 should "not include users with the 'only_owner' notification option" do
chris@37 1043 assert !@project.notified_users.include?(@only_owned_user)
chris@37 1044 end
chris@37 1045 end
chris@37 1046
Chris@0 1047 end