You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tracker_test.rb 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006- Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require_relative '../test_helper'
  19. class TrackerTest < ActiveSupport::TestCase
  20. fixtures :trackers, :workflows, :issue_statuses, :roles, :issues, :custom_fields, :projects, :projects_trackers, :enabled_modules
  21. def setup
  22. User.current = nil
  23. end
  24. def test_sorted_scope
  25. assert_equal Tracker.all.sort, Tracker.sorted.to_a
  26. end
  27. def test_named_scope
  28. assert_equal Tracker.find(2), Tracker.named('feature request').first
  29. end
  30. def test_visible_scope_chained_with_project_rolled_up_trackers
  31. project = Project.find(1)
  32. role = Role.generate!
  33. role.add_permission! :view_issues
  34. role.set_permission_trackers :view_issues, [2]
  35. role.save!
  36. user = User.generate!
  37. User.add_to_project user, project, role
  38. assert_equal [2], project.rolled_up_trackers(false).visible(user).map(&:id)
  39. end
  40. def test_copy_from
  41. tracker = Tracker.find(1)
  42. copy = Tracker.new.copy_from(tracker)
  43. assert_nil copy.id
  44. assert_nil copy.position
  45. assert_equal '', copy.name
  46. assert_equal tracker.default_status_id, copy.default_status_id
  47. assert_equal tracker.is_in_roadmap, copy.is_in_roadmap
  48. assert_equal tracker.core_fields, copy.core_fields
  49. assert_equal tracker.description, copy.description
  50. copy.name = 'Copy'
  51. assert copy.save
  52. end
  53. def test_copy_from_should_copy_custom_fields
  54. tracker = Tracker.generate!(:custom_field_ids => [1, 2, 6])
  55. copy = Tracker.new.copy_from(tracker)
  56. assert_equal [1, 2, 6], copy.custom_field_ids.sort
  57. end
  58. def test_copy_from_should_copy_projects
  59. tracker = Tracker.generate!(:project_ids => [1, 2, 3, 4, 5, 6])
  60. copy = Tracker.new.copy_from(tracker)
  61. assert_equal [1, 2, 3, 4, 5, 6], copy.project_ids.sort
  62. end
  63. def test_copy_workflows
  64. source = Tracker.find(1)
  65. rules_count = source.workflow_rules.count
  66. assert rules_count > 0
  67. target = Tracker.new(:name => 'Target', :default_status_id => 1)
  68. assert target.save
  69. target.copy_workflow_rules(source)
  70. target.reload
  71. assert_equal rules_count, target.workflow_rules.size
  72. end
  73. def test_issue_statuses
  74. tracker = Tracker.find(1)
  75. WorkflowTransition.delete_all
  76. WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 1)
  77. WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 2, :new_status_id => 3)
  78. WorkflowTransition.create!(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 5)
  79. assert_kind_of Array, tracker.issue_statuses
  80. assert_kind_of IssueStatus, tracker.issue_statuses.first
  81. assert_equal [2, 3, 5], Tracker.find(1).issue_statuses.collect(&:id)
  82. end
  83. def test_issue_statuses_empty
  84. WorkflowTransition.where(:tracker_id => 1).delete_all
  85. assert_equal [], Tracker.find(1).issue_statuses
  86. end
  87. def test_issue_statuses_should_be_empty_for_new_record
  88. assert_equal [], Tracker.new.issue_statuses
  89. end
  90. def test_core_fields_should_be_enabled_by_default
  91. tracker = Tracker.new
  92. assert_equal Tracker::CORE_FIELDS, tracker.core_fields
  93. assert_equal [], tracker.disabled_core_fields
  94. end
  95. def test_core_fields
  96. tracker = Tracker.new
  97. tracker.core_fields = %w(assigned_to_id due_date)
  98. assert_equal %w(assigned_to_id due_date), tracker.core_fields
  99. assert_equal Tracker::CORE_FIELDS - %w(assigned_to_id due_date), tracker.disabled_core_fields
  100. end
  101. def test_core_fields_should_return_fields_enabled_for_any_tracker
  102. trackers = []
  103. trackers << Tracker.new(:core_fields => %w(assigned_to_id due_date))
  104. trackers << Tracker.new(:core_fields => %w(assigned_to_id done_ratio))
  105. trackers << Tracker.new(:core_fields => [])
  106. assert_equal %w(assigned_to_id due_date done_ratio), Tracker.core_fields(trackers)
  107. assert_equal Tracker::CORE_FIELDS - %w(assigned_to_id due_date done_ratio), Tracker.disabled_core_fields(trackers)
  108. end
  109. def test_core_fields_should_return_all_fields_for_an_empty_argument
  110. assert_equal Tracker::CORE_FIELDS, Tracker.core_fields([])
  111. assert_equal [], Tracker.disabled_core_fields([])
  112. end
  113. def test_sort_should_sort_by_position
  114. a = Tracker.new(:name => 'Tracker A', :position => 2)
  115. b = Tracker.new(:name => 'Tracker B', :position => 1)
  116. assert_equal [b, a], [a, b].sort
  117. end
  118. def test_destroying_a_tracker_without_issues_should_not_raise_an_error
  119. tracker = Tracker.find(1)
  120. Issue.where(:tracker_id => tracker.id).delete_all
  121. assert_difference 'Tracker.count', -1 do
  122. assert_nothing_raised do
  123. tracker.destroy
  124. end
  125. end
  126. end
  127. def test_destroying_a_tracker_with_issues_should_raise_an_error
  128. tracker = Tracker.find(1)
  129. assert_no_difference 'Tracker.count' do
  130. assert_raise StandardError do
  131. tracker.destroy
  132. end
  133. end
  134. end
  135. def test_tracker_should_have_description
  136. tracker = Tracker.find(1)
  137. assert tracker.respond_to?(:description)
  138. assert_equal tracker.description, "Description for Bug tracker"
  139. end
  140. end