annotate .svn/pristine/90/904eff0611bb6a1b571fb9e08902d52f8956ee04.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +0100
parents e248c7af89ec
children
rev   line source
Chris@1494 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1494 3 #
Chris@1494 4 # This program is free software; you can redistribute it and/or
Chris@1494 5 # modify it under the terms of the GNU General Public License
Chris@1494 6 # as published by the Free Software Foundation; either version 2
Chris@1494 7 # of the License, or (at your option) any later version.
Chris@1494 8 #
Chris@1494 9 # This program is distributed in the hope that it will be useful,
Chris@1494 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1494 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1494 12 # GNU General Public License for more details.
Chris@1494 13 #
Chris@1494 14 # You should have received a copy of the GNU General Public License
Chris@1494 15 # along with this program; if not, write to the Free Software
Chris@1494 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1494 17
Chris@1494 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1494 19
Chris@1494 20 class ProjectTest < ActiveSupport::TestCase
Chris@1494 21 fixtures :projects, :trackers, :issue_statuses, :issues,
Chris@1494 22 :journals, :journal_details,
Chris@1494 23 :enumerations, :users, :issue_categories,
Chris@1494 24 :projects_trackers,
Chris@1494 25 :custom_fields,
Chris@1494 26 :custom_fields_projects,
Chris@1494 27 :custom_fields_trackers,
Chris@1494 28 :custom_values,
Chris@1494 29 :roles,
Chris@1494 30 :member_roles,
Chris@1494 31 :members,
Chris@1494 32 :enabled_modules,
Chris@1494 33 :versions,
Chris@1494 34 :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions,
Chris@1494 35 :groups_users,
Chris@1494 36 :boards, :messages,
Chris@1494 37 :repositories,
Chris@1494 38 :news, :comments,
Chris@1494 39 :documents
Chris@1494 40
Chris@1494 41 def setup
Chris@1494 42 @ecookbook = Project.find(1)
Chris@1494 43 @ecookbook_sub1 = Project.find(3)
Chris@1494 44 set_tmp_attachments_directory
Chris@1494 45 User.current = nil
Chris@1494 46 end
Chris@1494 47
Chris@1494 48 def test_truth
Chris@1494 49 assert_kind_of Project, @ecookbook
Chris@1494 50 assert_equal "eCookbook", @ecookbook.name
Chris@1494 51 end
Chris@1494 52
Chris@1494 53 def test_default_attributes
Chris@1494 54 with_settings :default_projects_public => '1' do
Chris@1494 55 assert_equal true, Project.new.is_public
Chris@1494 56 assert_equal false, Project.new(:is_public => false).is_public
Chris@1494 57 end
Chris@1494 58
Chris@1494 59 with_settings :default_projects_public => '0' do
Chris@1494 60 assert_equal false, Project.new.is_public
Chris@1494 61 assert_equal true, Project.new(:is_public => true).is_public
Chris@1494 62 end
Chris@1494 63
Chris@1494 64 with_settings :sequential_project_identifiers => '1' do
Chris@1494 65 assert !Project.new.identifier.blank?
Chris@1494 66 assert Project.new(:identifier => '').identifier.blank?
Chris@1494 67 end
Chris@1494 68
Chris@1494 69 with_settings :sequential_project_identifiers => '0' do
Chris@1494 70 assert Project.new.identifier.blank?
Chris@1494 71 assert !Project.new(:identifier => 'test').blank?
Chris@1494 72 end
Chris@1494 73
Chris@1494 74 with_settings :default_projects_modules => ['issue_tracking', 'repository'] do
Chris@1494 75 assert_equal ['issue_tracking', 'repository'], Project.new.enabled_module_names
Chris@1494 76 end
Chris@1494 77 end
Chris@1494 78
Chris@1494 79 def test_default_trackers_should_match_default_tracker_ids_setting
Chris@1494 80 with_settings :default_projects_tracker_ids => ['1', '3'] do
Chris@1494 81 assert_equal Tracker.find(1, 3).sort, Project.new.trackers.sort
Chris@1494 82 end
Chris@1494 83 end
Chris@1494 84
Chris@1494 85 def test_default_trackers_should_be_all_trackers_with_blank_setting
Chris@1494 86 with_settings :default_projects_tracker_ids => nil do
Chris@1494 87 assert_equal Tracker.all.sort, Project.new.trackers.sort
Chris@1494 88 end
Chris@1494 89 end
Chris@1494 90
Chris@1494 91 def test_default_trackers_should_be_empty_with_empty_setting
Chris@1494 92 with_settings :default_projects_tracker_ids => [] do
Chris@1494 93 assert_equal [], Project.new.trackers
Chris@1494 94 end
Chris@1494 95 end
Chris@1494 96
Chris@1494 97 def test_default_trackers_should_not_replace_initialized_trackers
Chris@1494 98 with_settings :default_projects_tracker_ids => ['1', '3'] do
Chris@1494 99 assert_equal Tracker.find(1, 2).sort, Project.new(:tracker_ids => [1, 2]).trackers.sort
Chris@1494 100 end
Chris@1494 101 end
Chris@1494 102
Chris@1494 103 def test_update
Chris@1494 104 assert_equal "eCookbook", @ecookbook.name
Chris@1494 105 @ecookbook.name = "eCook"
Chris@1494 106 assert @ecookbook.save, @ecookbook.errors.full_messages.join("; ")
Chris@1494 107 @ecookbook.reload
Chris@1494 108 assert_equal "eCook", @ecookbook.name
Chris@1494 109 end
Chris@1494 110
Chris@1494 111 def test_validate_identifier
Chris@1494 112 to_test = {"abc" => true,
Chris@1494 113 "ab12" => true,
Chris@1494 114 "ab-12" => true,
Chris@1494 115 "ab_12" => true,
Chris@1494 116 "12" => false,
Chris@1494 117 "new" => false}
Chris@1494 118
Chris@1494 119 to_test.each do |identifier, valid|
Chris@1494 120 p = Project.new
Chris@1494 121 p.identifier = identifier
Chris@1494 122 p.valid?
Chris@1494 123 if valid
Chris@1494 124 assert p.errors['identifier'].blank?, "identifier #{identifier} was not valid"
Chris@1494 125 else
Chris@1494 126 assert p.errors['identifier'].present?, "identifier #{identifier} was valid"
Chris@1494 127 end
Chris@1494 128 end
Chris@1494 129 end
Chris@1494 130
Chris@1494 131 def test_identifier_should_not_be_frozen_for_a_new_project
Chris@1494 132 assert_equal false, Project.new.identifier_frozen?
Chris@1494 133 end
Chris@1494 134
Chris@1494 135 def test_identifier_should_not_be_frozen_for_a_saved_project_with_blank_identifier
Chris@1494 136 Project.update_all(["identifier = ''"], "id = 1")
Chris@1494 137
Chris@1494 138 assert_equal false, Project.find(1).identifier_frozen?
Chris@1494 139 end
Chris@1494 140
Chris@1494 141 def test_identifier_should_be_frozen_for_a_saved_project_with_valid_identifier
Chris@1494 142 assert_equal true, Project.find(1).identifier_frozen?
Chris@1494 143 end
Chris@1494 144
Chris@1494 145 def test_members_should_be_active_users
Chris@1494 146 Project.all.each do |project|
Chris@1494 147 assert_nil project.members.detect {|m| !(m.user.is_a?(User) && m.user.active?) }
Chris@1494 148 end
Chris@1494 149 end
Chris@1494 150
Chris@1494 151 def test_users_should_be_active_users
Chris@1494 152 Project.all.each do |project|
Chris@1494 153 assert_nil project.users.detect {|u| !(u.is_a?(User) && u.active?) }
Chris@1494 154 end
Chris@1494 155 end
Chris@1494 156
Chris@1494 157 def test_open_scope_on_issues_association
Chris@1494 158 assert_kind_of Issue, Project.find(1).issues.open.first
Chris@1494 159 end
Chris@1494 160
Chris@1494 161 def test_archive
Chris@1494 162 user = @ecookbook.members.first.user
Chris@1494 163 @ecookbook.archive
Chris@1494 164 @ecookbook.reload
Chris@1494 165
Chris@1494 166 assert !@ecookbook.active?
Chris@1494 167 assert @ecookbook.archived?
Chris@1494 168 assert !user.projects.include?(@ecookbook)
Chris@1494 169 # Subproject are also archived
Chris@1494 170 assert !@ecookbook.children.empty?
Chris@1494 171 assert @ecookbook.descendants.active.empty?
Chris@1494 172 end
Chris@1494 173
Chris@1494 174 def test_archive_should_fail_if_versions_are_used_by_non_descendant_projects
Chris@1494 175 # Assign an issue of a project to a version of a child project
Chris@1494 176 Issue.find(4).update_attribute :fixed_version_id, 4
Chris@1494 177
Chris@1494 178 assert_no_difference "Project.where(:status => Project::STATUS_ARCHIVED).count" do
Chris@1494 179 assert_equal false, @ecookbook.archive
Chris@1494 180 end
Chris@1494 181 @ecookbook.reload
Chris@1494 182 assert @ecookbook.active?
Chris@1494 183 end
Chris@1494 184
Chris@1494 185 def test_unarchive
Chris@1494 186 user = @ecookbook.members.first.user
Chris@1494 187 @ecookbook.archive
Chris@1494 188 # A subproject of an archived project can not be unarchived
Chris@1494 189 assert !@ecookbook_sub1.unarchive
Chris@1494 190
Chris@1494 191 # Unarchive project
Chris@1494 192 assert @ecookbook.unarchive
Chris@1494 193 @ecookbook.reload
Chris@1494 194 assert @ecookbook.active?
Chris@1494 195 assert !@ecookbook.archived?
Chris@1494 196 assert user.projects.include?(@ecookbook)
Chris@1494 197 # Subproject can now be unarchived
Chris@1494 198 @ecookbook_sub1.reload
Chris@1494 199 assert @ecookbook_sub1.unarchive
Chris@1494 200 end
Chris@1494 201
Chris@1494 202 def test_destroy
Chris@1494 203 # 2 active members
Chris@1494 204 assert_equal 2, @ecookbook.members.size
Chris@1494 205 # and 1 is locked
Chris@1494 206 assert_equal 3, Member.where('project_id = ?', @ecookbook.id).all.size
Chris@1494 207 # some boards
Chris@1494 208 assert @ecookbook.boards.any?
Chris@1494 209
Chris@1494 210 @ecookbook.destroy
Chris@1494 211 # make sure that the project non longer exists
Chris@1494 212 assert_raise(ActiveRecord::RecordNotFound) { Project.find(@ecookbook.id) }
Chris@1494 213 # make sure related data was removed
Chris@1494 214 assert_nil Member.where(:project_id => @ecookbook.id).first
Chris@1494 215 assert_nil Board.where(:project_id => @ecookbook.id).first
Chris@1494 216 assert_nil Issue.where(:project_id => @ecookbook.id).first
Chris@1494 217 end
Chris@1494 218
Chris@1494 219 def test_destroy_should_destroy_subtasks
Chris@1494 220 issues = (0..2).to_a.map {Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => 1, :subject => 'test')}
Chris@1494 221 issues[0].update_attribute :parent_issue_id, issues[1].id
Chris@1494 222 issues[2].update_attribute :parent_issue_id, issues[1].id
Chris@1494 223 assert_equal 2, issues[1].children.count
Chris@1494 224
Chris@1494 225 assert_nothing_raised do
Chris@1494 226 Project.find(1).destroy
Chris@1494 227 end
Chris@1494 228 assert Issue.find_all_by_id(issues.map(&:id)).empty?
Chris@1494 229 end
Chris@1494 230
Chris@1494 231 def test_destroying_root_projects_should_clear_data
Chris@1494 232 Project.roots.each do |root|
Chris@1494 233 root.destroy
Chris@1494 234 end
Chris@1494 235
Chris@1494 236 assert_equal 0, Project.count, "Projects were not deleted: #{Project.all.inspect}"
Chris@1494 237 assert_equal 0, Member.count, "Members were not deleted: #{Member.all.inspect}"
Chris@1494 238 assert_equal 0, MemberRole.count
Chris@1494 239 assert_equal 0, Issue.count
Chris@1494 240 assert_equal 0, Journal.count
Chris@1494 241 assert_equal 0, JournalDetail.count
Chris@1494 242 assert_equal 0, Attachment.count, "Attachments were not deleted: #{Attachment.all.inspect}"
Chris@1494 243 assert_equal 0, EnabledModule.count
Chris@1494 244 assert_equal 0, IssueCategory.count
Chris@1494 245 assert_equal 0, IssueRelation.count
Chris@1494 246 assert_equal 0, Board.count
Chris@1494 247 assert_equal 0, Message.count
Chris@1494 248 assert_equal 0, News.count
Chris@1494 249 assert_equal 0, Query.where("project_id IS NOT NULL").count
Chris@1494 250 assert_equal 0, Repository.count
Chris@1494 251 assert_equal 0, Changeset.count
Chris@1494 252 assert_equal 0, Change.count
Chris@1494 253 assert_equal 0, Comment.count
Chris@1494 254 assert_equal 0, TimeEntry.count
Chris@1494 255 assert_equal 0, Version.count
Chris@1494 256 assert_equal 0, Watcher.count
Chris@1494 257 assert_equal 0, Wiki.count
Chris@1494 258 assert_equal 0, WikiPage.count
Chris@1494 259 assert_equal 0, WikiContent.count
Chris@1494 260 assert_equal 0, WikiContent::Version.count
Chris@1494 261 assert_equal 0, Project.connection.select_all("SELECT * FROM projects_trackers").size
Chris@1494 262 assert_equal 0, Project.connection.select_all("SELECT * FROM custom_fields_projects").size
Chris@1494 263 assert_equal 0, CustomValue.where(:customized_type => ['Project', 'Issue', 'TimeEntry', 'Version']).count
Chris@1494 264 end
Chris@1494 265
Chris@1494 266 def test_move_an_orphan_project_to_a_root_project
Chris@1494 267 sub = Project.find(2)
Chris@1494 268 sub.set_parent! @ecookbook
Chris@1494 269 assert_equal @ecookbook.id, sub.parent.id
Chris@1494 270 @ecookbook.reload
Chris@1494 271 assert_equal 4, @ecookbook.children.size
Chris@1494 272 end
Chris@1494 273
Chris@1494 274 def test_move_an_orphan_project_to_a_subproject
Chris@1494 275 sub = Project.find(2)
Chris@1494 276 assert sub.set_parent!(@ecookbook_sub1)
Chris@1494 277 end
Chris@1494 278
Chris@1494 279 def test_move_a_root_project_to_a_project
Chris@1494 280 sub = @ecookbook
Chris@1494 281 assert sub.set_parent!(Project.find(2))
Chris@1494 282 end
Chris@1494 283
Chris@1494 284 def test_should_not_move_a_project_to_its_children
Chris@1494 285 sub = @ecookbook
Chris@1494 286 assert !(sub.set_parent!(Project.find(3)))
Chris@1494 287 end
Chris@1494 288
Chris@1494 289 def test_set_parent_should_add_roots_in_alphabetical_order
Chris@1494 290 ProjectCustomField.delete_all
Chris@1494 291 Project.delete_all
Chris@1494 292 Project.create!(:name => 'Project C', :identifier => 'project-c').set_parent!(nil)
Chris@1494 293 Project.create!(:name => 'Project B', :identifier => 'project-b').set_parent!(nil)
Chris@1494 294 Project.create!(:name => 'Project D', :identifier => 'project-d').set_parent!(nil)
Chris@1494 295 Project.create!(:name => 'Project A', :identifier => 'project-a').set_parent!(nil)
Chris@1494 296
Chris@1494 297 assert_equal 4, Project.count
Chris@1494 298 assert_equal Project.all.sort_by(&:name), Project.all.sort_by(&:lft)
Chris@1494 299 end
Chris@1494 300
Chris@1494 301 def test_set_parent_should_add_children_in_alphabetical_order
Chris@1494 302 ProjectCustomField.delete_all
Chris@1494 303 parent = Project.create!(:name => 'Parent', :identifier => 'parent')
Chris@1494 304 Project.create!(:name => 'Project C', :identifier => 'project-c').set_parent!(parent)
Chris@1494 305 Project.create!(:name => 'Project B', :identifier => 'project-b').set_parent!(parent)
Chris@1494 306 Project.create!(:name => 'Project D', :identifier => 'project-d').set_parent!(parent)
Chris@1494 307 Project.create!(:name => 'Project A', :identifier => 'project-a').set_parent!(parent)
Chris@1494 308
Chris@1494 309 parent.reload
Chris@1494 310 assert_equal 4, parent.children.size
Chris@1494 311 assert_equal parent.children.all.sort_by(&:name), parent.children.all
Chris@1494 312 end
Chris@1494 313
Chris@1494 314 def test_set_parent_should_update_issue_fixed_version_associations_when_a_fixed_version_is_moved_out_of_the_hierarchy
Chris@1494 315 # Parent issue with a hierarchy project's fixed version
Chris@1494 316 parent_issue = Issue.find(1)
Chris@1494 317 parent_issue.update_attribute(:fixed_version_id, 4)
Chris@1494 318 parent_issue.reload
Chris@1494 319 assert_equal 4, parent_issue.fixed_version_id
Chris@1494 320
Chris@1494 321 # Should keep fixed versions for the issues
Chris@1494 322 issue_with_local_fixed_version = Issue.find(5)
Chris@1494 323 issue_with_local_fixed_version.update_attribute(:fixed_version_id, 4)
Chris@1494 324 issue_with_local_fixed_version.reload
Chris@1494 325 assert_equal 4, issue_with_local_fixed_version.fixed_version_id
Chris@1494 326
Chris@1494 327 # Local issue with hierarchy fixed_version
Chris@1494 328 issue_with_hierarchy_fixed_version = Issue.find(13)
Chris@1494 329 issue_with_hierarchy_fixed_version.update_attribute(:fixed_version_id, 6)
Chris@1494 330 issue_with_hierarchy_fixed_version.reload
Chris@1494 331 assert_equal 6, issue_with_hierarchy_fixed_version.fixed_version_id
Chris@1494 332
Chris@1494 333 # Move project out of the issue's hierarchy
Chris@1494 334 moved_project = Project.find(3)
Chris@1494 335 moved_project.set_parent!(Project.find(2))
Chris@1494 336 parent_issue.reload
Chris@1494 337 issue_with_local_fixed_version.reload
Chris@1494 338 issue_with_hierarchy_fixed_version.reload
Chris@1494 339
Chris@1494 340 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@1494 341 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@1494 342 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@1494 343 end
Chris@1494 344
Chris@1494 345 def test_parent
Chris@1494 346 p = Project.find(6).parent
Chris@1494 347 assert p.is_a?(Project)
Chris@1494 348 assert_equal 5, p.id
Chris@1494 349 end
Chris@1494 350
Chris@1494 351 def test_ancestors
Chris@1494 352 a = Project.find(6).ancestors
Chris@1494 353 assert a.first.is_a?(Project)
Chris@1494 354 assert_equal [1, 5], a.collect(&:id)
Chris@1494 355 end
Chris@1494 356
Chris@1494 357 def test_root
Chris@1494 358 r = Project.find(6).root
Chris@1494 359 assert r.is_a?(Project)
Chris@1494 360 assert_equal 1, r.id
Chris@1494 361 end
Chris@1494 362
Chris@1494 363 def test_children
Chris@1494 364 c = Project.find(1).children
Chris@1494 365 assert c.first.is_a?(Project)
Chris@1494 366 assert_equal [5, 3, 4], c.collect(&:id)
Chris@1494 367 end
Chris@1494 368
Chris@1494 369 def test_descendants
Chris@1494 370 d = Project.find(1).descendants
Chris@1494 371 assert d.first.is_a?(Project)
Chris@1494 372 assert_equal [5, 6, 3, 4], d.collect(&:id)
Chris@1494 373 end
Chris@1494 374
Chris@1494 375 def test_allowed_parents_should_be_empty_for_non_member_user
Chris@1494 376 Role.non_member.add_permission!(:add_project)
Chris@1494 377 user = User.find(9)
Chris@1494 378 assert user.memberships.empty?
Chris@1494 379 User.current = user
Chris@1494 380 assert Project.new.allowed_parents.compact.empty?
Chris@1494 381 end
Chris@1494 382
Chris@1494 383 def test_allowed_parents_with_add_subprojects_permission
Chris@1494 384 Role.find(1).remove_permission!(:add_project)
Chris@1494 385 Role.find(1).add_permission!(:add_subprojects)
Chris@1494 386 User.current = User.find(2)
Chris@1494 387 # new project
Chris@1494 388 assert !Project.new.allowed_parents.include?(nil)
Chris@1494 389 assert Project.new.allowed_parents.include?(Project.find(1))
Chris@1494 390 # existing root project
Chris@1494 391 assert Project.find(1).allowed_parents.include?(nil)
Chris@1494 392 # existing child
Chris@1494 393 assert Project.find(3).allowed_parents.include?(Project.find(1))
Chris@1494 394 assert !Project.find(3).allowed_parents.include?(nil)
Chris@1494 395 end
Chris@1494 396
Chris@1494 397 def test_allowed_parents_with_add_project_permission
Chris@1494 398 Role.find(1).add_permission!(:add_project)
Chris@1494 399 Role.find(1).remove_permission!(:add_subprojects)
Chris@1494 400 User.current = User.find(2)
Chris@1494 401 # new project
Chris@1494 402 assert Project.new.allowed_parents.include?(nil)
Chris@1494 403 assert !Project.new.allowed_parents.include?(Project.find(1))
Chris@1494 404 # existing root project
Chris@1494 405 assert Project.find(1).allowed_parents.include?(nil)
Chris@1494 406 # existing child
Chris@1494 407 assert Project.find(3).allowed_parents.include?(Project.find(1))
Chris@1494 408 assert Project.find(3).allowed_parents.include?(nil)
Chris@1494 409 end
Chris@1494 410
Chris@1494 411 def test_allowed_parents_with_add_project_and_subprojects_permission
Chris@1494 412 Role.find(1).add_permission!(:add_project)
Chris@1494 413 Role.find(1).add_permission!(:add_subprojects)
Chris@1494 414 User.current = User.find(2)
Chris@1494 415 # new project
Chris@1494 416 assert Project.new.allowed_parents.include?(nil)
Chris@1494 417 assert Project.new.allowed_parents.include?(Project.find(1))
Chris@1494 418 # existing root project
Chris@1494 419 assert Project.find(1).allowed_parents.include?(nil)
Chris@1494 420 # existing child
Chris@1494 421 assert Project.find(3).allowed_parents.include?(Project.find(1))
Chris@1494 422 assert Project.find(3).allowed_parents.include?(nil)
Chris@1494 423 end
Chris@1494 424
Chris@1494 425 def test_users_by_role
Chris@1494 426 users_by_role = Project.find(1).users_by_role
Chris@1494 427 assert_kind_of Hash, users_by_role
Chris@1494 428 role = Role.find(1)
Chris@1494 429 assert_kind_of Array, users_by_role[role]
Chris@1494 430 assert users_by_role[role].include?(User.find(2))
Chris@1494 431 end
Chris@1494 432
Chris@1494 433 def test_rolled_up_trackers
Chris@1494 434 parent = Project.find(1)
Chris@1494 435 parent.trackers = Tracker.find([1,2])
Chris@1494 436 child = parent.children.find(3)
Chris@1494 437
Chris@1494 438 assert_equal [1, 2], parent.tracker_ids
Chris@1494 439 assert_equal [2, 3], child.trackers.collect(&:id)
Chris@1494 440
Chris@1494 441 assert_kind_of Tracker, parent.rolled_up_trackers.first
Chris@1494 442 assert_equal Tracker.find(1), parent.rolled_up_trackers.first
Chris@1494 443
Chris@1494 444 assert_equal [1, 2, 3], parent.rolled_up_trackers.collect(&:id)
Chris@1494 445 assert_equal [2, 3], child.rolled_up_trackers.collect(&:id)
Chris@1494 446 end
Chris@1494 447
Chris@1494 448 def test_rolled_up_trackers_should_ignore_archived_subprojects
Chris@1494 449 parent = Project.find(1)
Chris@1494 450 parent.trackers = Tracker.find([1,2])
Chris@1494 451 child = parent.children.find(3)
Chris@1494 452 child.trackers = Tracker.find([1,3])
Chris@1494 453 parent.children.each(&:archive)
Chris@1494 454
Chris@1494 455 assert_equal [1,2], parent.rolled_up_trackers.collect(&:id)
Chris@1494 456 end
Chris@1494 457
Chris@1494 458 test "#rolled_up_trackers should ignore projects with issue_tracking module disabled" do
Chris@1494 459 parent = Project.generate!
Chris@1494 460 parent.trackers = Tracker.find([1, 2])
Chris@1494 461 child = Project.generate_with_parent!(parent)
Chris@1494 462 child.trackers = Tracker.find([2, 3])
Chris@1494 463
Chris@1494 464 assert_equal [1, 2, 3], parent.rolled_up_trackers.collect(&:id).sort
Chris@1494 465
Chris@1494 466 assert child.disable_module!(:issue_tracking)
Chris@1494 467 parent.reload
Chris@1494 468 assert_equal [1, 2], parent.rolled_up_trackers.collect(&:id).sort
Chris@1494 469 end
Chris@1494 470
Chris@1494 471 test "#rolled_up_versions should include the versions for the current project" do
Chris@1494 472 project = Project.generate!
Chris@1494 473 parent_version_1 = Version.generate!(:project => project)
Chris@1494 474 parent_version_2 = Version.generate!(:project => project)
Chris@1494 475 assert_same_elements [parent_version_1, parent_version_2], project.rolled_up_versions
Chris@1494 476 end
Chris@1494 477
Chris@1494 478 test "#rolled_up_versions should include versions for a subproject" do
Chris@1494 479 project = Project.generate!
Chris@1494 480 parent_version_1 = Version.generate!(:project => project)
Chris@1494 481 parent_version_2 = Version.generate!(:project => project)
Chris@1494 482 subproject = Project.generate_with_parent!(project)
Chris@1494 483 subproject_version = Version.generate!(:project => subproject)
Chris@1494 484
Chris@1494 485 assert_same_elements [
Chris@1494 486 parent_version_1,
Chris@1494 487 parent_version_2,
Chris@1494 488 subproject_version
Chris@1494 489 ], project.rolled_up_versions
Chris@1494 490 end
Chris@1494 491
Chris@1494 492 test "#rolled_up_versions should include versions for a sub-subproject" do
Chris@1494 493 project = Project.generate!
Chris@1494 494 parent_version_1 = Version.generate!(:project => project)
Chris@1494 495 parent_version_2 = Version.generate!(:project => project)
Chris@1494 496 subproject = Project.generate_with_parent!(project)
Chris@1494 497 sub_subproject = Project.generate_with_parent!(subproject)
Chris@1494 498 sub_subproject_version = Version.generate!(:project => sub_subproject)
Chris@1494 499 project.reload
Chris@1494 500
Chris@1494 501 assert_same_elements [
Chris@1494 502 parent_version_1,
Chris@1494 503 parent_version_2,
Chris@1494 504 sub_subproject_version
Chris@1494 505 ], project.rolled_up_versions
Chris@1494 506 end
Chris@1494 507
Chris@1494 508 test "#rolled_up_versions should only check active projects" do
Chris@1494 509 project = Project.generate!
Chris@1494 510 parent_version_1 = Version.generate!(:project => project)
Chris@1494 511 parent_version_2 = Version.generate!(:project => project)
Chris@1494 512 subproject = Project.generate_with_parent!(project)
Chris@1494 513 subproject_version = Version.generate!(:project => subproject)
Chris@1494 514 assert subproject.archive
Chris@1494 515 project.reload
Chris@1494 516
Chris@1494 517 assert !subproject.active?
Chris@1494 518 assert_same_elements [parent_version_1, parent_version_2], project.rolled_up_versions
Chris@1494 519 end
Chris@1494 520
Chris@1494 521 def test_shared_versions_none_sharing
Chris@1494 522 p = Project.find(5)
Chris@1494 523 v = Version.create!(:name => 'none_sharing', :project => p, :sharing => 'none')
Chris@1494 524 assert p.shared_versions.include?(v)
Chris@1494 525 assert !p.children.first.shared_versions.include?(v)
Chris@1494 526 assert !p.root.shared_versions.include?(v)
Chris@1494 527 assert !p.siblings.first.shared_versions.include?(v)
Chris@1494 528 assert !p.root.siblings.first.shared_versions.include?(v)
Chris@1494 529 end
Chris@1494 530
Chris@1494 531 def test_shared_versions_descendants_sharing
Chris@1494 532 p = Project.find(5)
Chris@1494 533 v = Version.create!(:name => 'descendants_sharing', :project => p, :sharing => 'descendants')
Chris@1494 534 assert p.shared_versions.include?(v)
Chris@1494 535 assert p.children.first.shared_versions.include?(v)
Chris@1494 536 assert !p.root.shared_versions.include?(v)
Chris@1494 537 assert !p.siblings.first.shared_versions.include?(v)
Chris@1494 538 assert !p.root.siblings.first.shared_versions.include?(v)
Chris@1494 539 end
Chris@1494 540
Chris@1494 541 def test_shared_versions_hierarchy_sharing
Chris@1494 542 p = Project.find(5)
Chris@1494 543 v = Version.create!(:name => 'hierarchy_sharing', :project => p, :sharing => 'hierarchy')
Chris@1494 544 assert p.shared_versions.include?(v)
Chris@1494 545 assert p.children.first.shared_versions.include?(v)
Chris@1494 546 assert p.root.shared_versions.include?(v)
Chris@1494 547 assert !p.siblings.first.shared_versions.include?(v)
Chris@1494 548 assert !p.root.siblings.first.shared_versions.include?(v)
Chris@1494 549 end
Chris@1494 550
Chris@1494 551 def test_shared_versions_tree_sharing
Chris@1494 552 p = Project.find(5)
Chris@1494 553 v = Version.create!(:name => 'tree_sharing', :project => p, :sharing => 'tree')
Chris@1494 554 assert p.shared_versions.include?(v)
Chris@1494 555 assert p.children.first.shared_versions.include?(v)
Chris@1494 556 assert p.root.shared_versions.include?(v)
Chris@1494 557 assert p.siblings.first.shared_versions.include?(v)
Chris@1494 558 assert !p.root.siblings.first.shared_versions.include?(v)
Chris@1494 559 end
Chris@1494 560
Chris@1494 561 def test_shared_versions_system_sharing
Chris@1494 562 p = Project.find(5)
Chris@1494 563 v = Version.create!(:name => 'system_sharing', :project => p, :sharing => 'system')
Chris@1494 564 assert p.shared_versions.include?(v)
Chris@1494 565 assert p.children.first.shared_versions.include?(v)
Chris@1494 566 assert p.root.shared_versions.include?(v)
Chris@1494 567 assert p.siblings.first.shared_versions.include?(v)
Chris@1494 568 assert p.root.siblings.first.shared_versions.include?(v)
Chris@1494 569 end
Chris@1494 570
Chris@1494 571 def test_shared_versions
Chris@1494 572 parent = Project.find(1)
Chris@1494 573 child = parent.children.find(3)
Chris@1494 574 private_child = parent.children.find(5)
Chris@1494 575
Chris@1494 576 assert_equal [1,2,3], parent.version_ids.sort
Chris@1494 577 assert_equal [4], child.version_ids
Chris@1494 578 assert_equal [6], private_child.version_ids
Chris@1494 579 assert_equal [7], Version.find_all_by_sharing('system').collect(&:id)
Chris@1494 580
Chris@1494 581 assert_equal 6, parent.shared_versions.size
Chris@1494 582 parent.shared_versions.each do |version|
Chris@1494 583 assert_kind_of Version, version
Chris@1494 584 end
Chris@1494 585
Chris@1494 586 assert_equal [1,2,3,4,6,7], parent.shared_versions.collect(&:id).sort
Chris@1494 587 end
Chris@1494 588
Chris@1494 589 def test_shared_versions_should_ignore_archived_subprojects
Chris@1494 590 parent = Project.find(1)
Chris@1494 591 child = parent.children.find(3)
Chris@1494 592 child.archive
Chris@1494 593 parent.reload
Chris@1494 594
Chris@1494 595 assert_equal [1,2,3], parent.version_ids.sort
Chris@1494 596 assert_equal [4], child.version_ids
Chris@1494 597 assert !parent.shared_versions.collect(&:id).include?(4)
Chris@1494 598 end
Chris@1494 599
Chris@1494 600 def test_shared_versions_visible_to_user
Chris@1494 601 user = User.find(3)
Chris@1494 602 parent = Project.find(1)
Chris@1494 603 child = parent.children.find(5)
Chris@1494 604
Chris@1494 605 assert_equal [1,2,3], parent.version_ids.sort
Chris@1494 606 assert_equal [6], child.version_ids
Chris@1494 607
Chris@1494 608 versions = parent.shared_versions.visible(user)
Chris@1494 609
Chris@1494 610 assert_equal 4, versions.size
Chris@1494 611 versions.each do |version|
Chris@1494 612 assert_kind_of Version, version
Chris@1494 613 end
Chris@1494 614
Chris@1494 615 assert !versions.collect(&:id).include?(6)
Chris@1494 616 end
Chris@1494 617
Chris@1494 618 def test_shared_versions_for_new_project_should_include_system_shared_versions
Chris@1494 619 p = Project.find(5)
Chris@1494 620 v = Version.create!(:name => 'system_sharing', :project => p, :sharing => 'system')
Chris@1494 621
Chris@1494 622 assert_include v, Project.new.shared_versions
Chris@1494 623 end
Chris@1494 624
Chris@1494 625 def test_next_identifier
Chris@1494 626 ProjectCustomField.delete_all
Chris@1494 627 Project.create!(:name => 'last', :identifier => 'p2008040')
Chris@1494 628 assert_equal 'p2008041', Project.next_identifier
Chris@1494 629 end
Chris@1494 630
Chris@1494 631 def test_next_identifier_first_project
Chris@1494 632 Project.delete_all
Chris@1494 633 assert_nil Project.next_identifier
Chris@1494 634 end
Chris@1494 635
Chris@1494 636 def test_enabled_module_names
Chris@1494 637 with_settings :default_projects_modules => ['issue_tracking', 'repository'] do
Chris@1494 638 project = Project.new
Chris@1494 639
Chris@1494 640 project.enabled_module_names = %w(issue_tracking news)
Chris@1494 641 assert_equal %w(issue_tracking news), project.enabled_module_names.sort
Chris@1494 642 end
Chris@1494 643 end
Chris@1494 644
Chris@1494 645 test "enabled_modules should define module by names and preserve ids" do
Chris@1494 646 @project = Project.find(1)
Chris@1494 647 # Remove one module
Chris@1494 648 modules = @project.enabled_modules.slice(0..-2)
Chris@1494 649 assert modules.any?
Chris@1494 650 assert_difference 'EnabledModule.count', -1 do
Chris@1494 651 @project.enabled_module_names = modules.collect(&:name)
Chris@1494 652 end
Chris@1494 653 @project.reload
Chris@1494 654 # Ids should be preserved
Chris@1494 655 assert_equal @project.enabled_module_ids.sort, modules.collect(&:id).sort
Chris@1494 656 end
Chris@1494 657
Chris@1494 658 test "enabled_modules should enable a module" do
Chris@1494 659 @project = Project.find(1)
Chris@1494 660 @project.enabled_module_names = []
Chris@1494 661 @project.reload
Chris@1494 662 assert_equal [], @project.enabled_module_names
Chris@1494 663 #with string
Chris@1494 664 @project.enable_module!("issue_tracking")
Chris@1494 665 assert_equal ["issue_tracking"], @project.enabled_module_names
Chris@1494 666 #with symbol
Chris@1494 667 @project.enable_module!(:gantt)
Chris@1494 668 assert_equal ["issue_tracking", "gantt"], @project.enabled_module_names
Chris@1494 669 #don't add a module twice
Chris@1494 670 @project.enable_module!("issue_tracking")
Chris@1494 671 assert_equal ["issue_tracking", "gantt"], @project.enabled_module_names
Chris@1494 672 end
Chris@1494 673
Chris@1494 674 test "enabled_modules should disable a module" do
Chris@1494 675 @project = Project.find(1)
Chris@1494 676 #with string
Chris@1494 677 assert @project.enabled_module_names.include?("issue_tracking")
Chris@1494 678 @project.disable_module!("issue_tracking")
Chris@1494 679 assert ! @project.reload.enabled_module_names.include?("issue_tracking")
Chris@1494 680 #with symbol
Chris@1494 681 assert @project.enabled_module_names.include?("gantt")
Chris@1494 682 @project.disable_module!(:gantt)
Chris@1494 683 assert ! @project.reload.enabled_module_names.include?("gantt")
Chris@1494 684 #with EnabledModule object
Chris@1494 685 first_module = @project.enabled_modules.first
Chris@1494 686 @project.disable_module!(first_module)
Chris@1494 687 assert ! @project.reload.enabled_module_names.include?(first_module.name)
Chris@1494 688 end
Chris@1494 689
Chris@1494 690 def test_enabled_module_names_should_not_recreate_enabled_modules
Chris@1494 691 project = Project.find(1)
Chris@1494 692 # Remove one module
Chris@1494 693 modules = project.enabled_modules.slice(0..-2)
Chris@1494 694 assert modules.any?
Chris@1494 695 assert_difference 'EnabledModule.count', -1 do
Chris@1494 696 project.enabled_module_names = modules.collect(&:name)
Chris@1494 697 end
Chris@1494 698 project.reload
Chris@1494 699 # Ids should be preserved
Chris@1494 700 assert_equal project.enabled_module_ids.sort, modules.collect(&:id).sort
Chris@1494 701 end
Chris@1494 702
Chris@1494 703 def test_copy_from_existing_project
Chris@1494 704 source_project = Project.find(1)
Chris@1494 705 copied_project = Project.copy_from(1)
Chris@1494 706
Chris@1494 707 assert copied_project
Chris@1494 708 # Cleared attributes
Chris@1494 709 assert copied_project.id.blank?
Chris@1494 710 assert copied_project.name.blank?
Chris@1494 711 assert copied_project.identifier.blank?
Chris@1494 712
Chris@1494 713 # Duplicated attributes
Chris@1494 714 assert_equal source_project.description, copied_project.description
Chris@1494 715 assert_equal source_project.enabled_modules, copied_project.enabled_modules
Chris@1494 716 assert_equal source_project.trackers, copied_project.trackers
Chris@1494 717
Chris@1494 718 # Default attributes
Chris@1494 719 assert_equal 1, copied_project.status
Chris@1494 720 end
Chris@1494 721
Chris@1494 722 def test_activities_should_use_the_system_activities
Chris@1494 723 project = Project.find(1)
Chris@1494 724 assert_equal project.activities, TimeEntryActivity.where(:active => true).all
Chris@1494 725 end
Chris@1494 726
Chris@1494 727
Chris@1494 728 def test_activities_should_use_the_project_specific_activities
Chris@1494 729 project = Project.find(1)
Chris@1494 730 overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project})
Chris@1494 731 assert overridden_activity.save!
Chris@1494 732
Chris@1494 733 assert project.activities.include?(overridden_activity), "Project specific Activity not found"
Chris@1494 734 end
Chris@1494 735
Chris@1494 736 def test_activities_should_not_include_the_inactive_project_specific_activities
Chris@1494 737 project = Project.find(1)
Chris@1494 738 overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => TimeEntryActivity.first, :active => false})
Chris@1494 739 assert overridden_activity.save!
Chris@1494 740
Chris@1494 741 assert !project.activities.include?(overridden_activity), "Inactive Project specific Activity found"
Chris@1494 742 end
Chris@1494 743
Chris@1494 744 def test_activities_should_not_include_project_specific_activities_from_other_projects
Chris@1494 745 project = Project.find(1)
Chris@1494 746 overridden_activity = TimeEntryActivity.new({:name => "Project", :project => Project.find(2)})
Chris@1494 747 assert overridden_activity.save!
Chris@1494 748
Chris@1494 749 assert !project.activities.include?(overridden_activity), "Project specific Activity found on a different project"
Chris@1494 750 end
Chris@1494 751
Chris@1494 752 def test_activities_should_handle_nils
Chris@1494 753 overridden_activity = TimeEntryActivity.new({:name => "Project", :project => Project.find(1), :parent => TimeEntryActivity.first})
Chris@1494 754 TimeEntryActivity.delete_all
Chris@1494 755
Chris@1494 756 # No activities
Chris@1494 757 project = Project.find(1)
Chris@1494 758 assert project.activities.empty?
Chris@1494 759
Chris@1494 760 # No system, one overridden
Chris@1494 761 assert overridden_activity.save!
Chris@1494 762 project.reload
Chris@1494 763 assert_equal [overridden_activity], project.activities
Chris@1494 764 end
Chris@1494 765
Chris@1494 766 def test_activities_should_override_system_activities_with_project_activities
Chris@1494 767 project = Project.find(1)
Chris@1494 768 parent_activity = TimeEntryActivity.first
Chris@1494 769 overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => parent_activity})
Chris@1494 770 assert overridden_activity.save!
Chris@1494 771
Chris@1494 772 assert project.activities.include?(overridden_activity), "Project specific Activity not found"
Chris@1494 773 assert !project.activities.include?(parent_activity), "System Activity found when it should have been overridden"
Chris@1494 774 end
Chris@1494 775
Chris@1494 776 def test_activities_should_include_inactive_activities_if_specified
Chris@1494 777 project = Project.find(1)
Chris@1494 778 overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => TimeEntryActivity.first, :active => false})
Chris@1494 779 assert overridden_activity.save!
Chris@1494 780
Chris@1494 781 assert project.activities(true).include?(overridden_activity), "Inactive Project specific Activity not found"
Chris@1494 782 end
Chris@1494 783
Chris@1494 784 test 'activities should not include active System activities if the project has an override that is inactive' do
Chris@1494 785 project = Project.find(1)
Chris@1494 786 system_activity = TimeEntryActivity.find_by_name('Design')
Chris@1494 787 assert system_activity.active?
Chris@1494 788 overridden_activity = TimeEntryActivity.create!(:name => "Project", :project => project, :parent => system_activity, :active => false)
Chris@1494 789 assert overridden_activity.save!
Chris@1494 790
Chris@1494 791 assert !project.activities.include?(overridden_activity), "Inactive Project specific Activity not found"
Chris@1494 792 assert !project.activities.include?(system_activity), "System activity found when the project has an inactive override"
Chris@1494 793 end
Chris@1494 794
Chris@1494 795 def test_close_completed_versions
Chris@1494 796 Version.update_all("status = 'open'")
Chris@1494 797 project = Project.find(1)
Chris@1494 798 assert_not_nil project.versions.detect {|v| v.completed? && v.status == 'open'}
Chris@1494 799 assert_not_nil project.versions.detect {|v| !v.completed? && v.status == 'open'}
Chris@1494 800 project.close_completed_versions
Chris@1494 801 project.reload
Chris@1494 802 assert_nil project.versions.detect {|v| v.completed? && v.status != 'closed'}
Chris@1494 803 assert_not_nil project.versions.detect {|v| !v.completed? && v.status == 'open'}
Chris@1494 804 end
Chris@1494 805
Chris@1494 806 test "#start_date should be nil if there are no issues on the project" do
Chris@1494 807 project = Project.generate!
Chris@1494 808 assert_nil project.start_date
Chris@1494 809 end
Chris@1494 810
Chris@1494 811 test "#start_date should be nil when issues have no start date" do
Chris@1494 812 project = Project.generate!
Chris@1494 813 project.trackers << Tracker.generate!
Chris@1494 814 early = 7.days.ago.to_date
Chris@1494 815 Issue.generate!(:project => project, :start_date => nil)
Chris@1494 816
Chris@1494 817 assert_nil project.start_date
Chris@1494 818 end
Chris@1494 819
Chris@1494 820 test "#start_date should be the earliest start date of it's issues" do
Chris@1494 821 project = Project.generate!
Chris@1494 822 project.trackers << Tracker.generate!
Chris@1494 823 early = 7.days.ago.to_date
Chris@1494 824 Issue.generate!(:project => project, :start_date => Date.today)
Chris@1494 825 Issue.generate!(:project => project, :start_date => early)
Chris@1494 826
Chris@1494 827 assert_equal early, project.start_date
Chris@1494 828 end
Chris@1494 829
Chris@1494 830 test "#due_date should be nil if there are no issues on the project" do
Chris@1494 831 project = Project.generate!
Chris@1494 832 assert_nil project.due_date
Chris@1494 833 end
Chris@1494 834
Chris@1494 835 test "#due_date should be nil if there are no issues with due dates" do
Chris@1494 836 project = Project.generate!
Chris@1494 837 project.trackers << Tracker.generate!
Chris@1494 838 Issue.generate!(:project => project, :due_date => nil)
Chris@1494 839
Chris@1494 840 assert_nil project.due_date
Chris@1494 841 end
Chris@1494 842
Chris@1494 843 test "#due_date should be the latest due date of it's issues" do
Chris@1494 844 project = Project.generate!
Chris@1494 845 project.trackers << Tracker.generate!
Chris@1494 846 future = 7.days.from_now.to_date
Chris@1494 847 Issue.generate!(:project => project, :due_date => future)
Chris@1494 848 Issue.generate!(:project => project, :due_date => Date.today)
Chris@1494 849
Chris@1494 850 assert_equal future, project.due_date
Chris@1494 851 end
Chris@1494 852
Chris@1494 853 test "#due_date should be the latest due date of it's versions" do
Chris@1494 854 project = Project.generate!
Chris@1494 855 future = 7.days.from_now.to_date
Chris@1494 856 project.versions << Version.generate!(:effective_date => future)
Chris@1494 857 project.versions << Version.generate!(:effective_date => Date.today)
Chris@1494 858
Chris@1494 859 assert_equal future, project.due_date
Chris@1494 860 end
Chris@1494 861
Chris@1494 862 test "#due_date should pick the latest date from it's issues and versions" do
Chris@1494 863 project = Project.generate!
Chris@1494 864 project.trackers << Tracker.generate!
Chris@1494 865 future = 7.days.from_now.to_date
Chris@1494 866 far_future = 14.days.from_now.to_date
Chris@1494 867 Issue.generate!(:project => project, :due_date => far_future)
Chris@1494 868 project.versions << Version.generate!(:effective_date => future)
Chris@1494 869
Chris@1494 870 assert_equal far_future, project.due_date
Chris@1494 871 end
Chris@1494 872
Chris@1494 873 test "#completed_percent with no versions should be 100" do
Chris@1494 874 project = Project.generate!
Chris@1494 875 assert_equal 100, project.completed_percent
Chris@1494 876 end
Chris@1494 877
Chris@1494 878 test "#completed_percent with versions should return 0 if the versions have no issues" do
Chris@1494 879 project = Project.generate!
Chris@1494 880 Version.generate!(:project => project)
Chris@1494 881 Version.generate!(:project => project)
Chris@1494 882
Chris@1494 883 assert_equal 0, project.completed_percent
Chris@1494 884 end
Chris@1494 885
Chris@1494 886 test "#completed_percent with versions should return 100 if the version has only closed issues" do
Chris@1494 887 project = Project.generate!
Chris@1494 888 project.trackers << Tracker.generate!
Chris@1494 889 v1 = Version.generate!(:project => project)
Chris@1494 890 Issue.generate!(:project => project, :status => IssueStatus.find_by_name('Closed'), :fixed_version => v1)
Chris@1494 891 v2 = Version.generate!(:project => project)
Chris@1494 892 Issue.generate!(:project => project, :status => IssueStatus.find_by_name('Closed'), :fixed_version => v2)
Chris@1494 893
Chris@1494 894 assert_equal 100, project.completed_percent
Chris@1494 895 end
Chris@1494 896
Chris@1494 897 test "#completed_percent with versions should return the averaged completed percent of the versions (not weighted)" do
Chris@1494 898 project = Project.generate!
Chris@1494 899 project.trackers << Tracker.generate!
Chris@1494 900 v1 = Version.generate!(:project => project)
Chris@1494 901 Issue.generate!(:project => project, :status => IssueStatus.find_by_name('New'), :estimated_hours => 10, :done_ratio => 50, :fixed_version => v1)
Chris@1494 902 v2 = Version.generate!(:project => project)
Chris@1494 903 Issue.generate!(:project => project, :status => IssueStatus.find_by_name('New'), :estimated_hours => 10, :done_ratio => 50, :fixed_version => v2)
Chris@1494 904
Chris@1494 905 assert_equal 50, project.completed_percent
Chris@1494 906 end
Chris@1494 907
Chris@1494 908 test "#notified_users" do
Chris@1494 909 project = Project.generate!
Chris@1494 910 role = Role.generate!
Chris@1494 911
Chris@1494 912 user_with_membership_notification = User.generate!(:mail_notification => 'selected')
Chris@1494 913 Member.create!(:project => project, :roles => [role], :principal => user_with_membership_notification, :mail_notification => true)
Chris@1494 914
Chris@1494 915 all_events_user = User.generate!(:mail_notification => 'all')
Chris@1494 916 Member.create!(:project => project, :roles => [role], :principal => all_events_user)
Chris@1494 917
Chris@1494 918 no_events_user = User.generate!(:mail_notification => 'none')
Chris@1494 919 Member.create!(:project => project, :roles => [role], :principal => no_events_user)
Chris@1494 920
Chris@1494 921 only_my_events_user = User.generate!(:mail_notification => 'only_my_events')
Chris@1494 922 Member.create!(:project => project, :roles => [role], :principal => only_my_events_user)
Chris@1494 923
Chris@1494 924 only_assigned_user = User.generate!(:mail_notification => 'only_assigned')
Chris@1494 925 Member.create!(:project => project, :roles => [role], :principal => only_assigned_user)
Chris@1494 926
Chris@1494 927 only_owned_user = User.generate!(:mail_notification => 'only_owner')
Chris@1494 928 Member.create!(:project => project, :roles => [role], :principal => only_owned_user)
Chris@1494 929
Chris@1494 930 assert project.notified_users.include?(user_with_membership_notification), "should include members with a mail notification"
Chris@1494 931 assert project.notified_users.include?(all_events_user), "should include users with the 'all' notification option"
Chris@1494 932 assert !project.notified_users.include?(no_events_user), "should not include users with the 'none' notification option"
Chris@1494 933 assert !project.notified_users.include?(only_my_events_user), "should not include users with the 'only_my_events' notification option"
Chris@1494 934 assert !project.notified_users.include?(only_assigned_user), "should not include users with the 'only_assigned' notification option"
Chris@1494 935 assert !project.notified_users.include?(only_owned_user), "should not include users with the 'only_owner' notification option"
Chris@1494 936 end
Chris@1494 937 end