annotate .svn/pristine/08/0857a2b98bb983778cfcdfd0cbe755f5b48aa4d8.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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