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 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2017 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 File.expand_path('../../test_helper', __FILE__)
  19. class TrackerTest < ActiveSupport::TestCase
  20. fixtures :trackers, :workflows, :issue_statuses, :roles, :issues, :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_workflows
  41. source = Tracker.find(1)
  42. rules_count = source.workflow_rules.count
  43. assert rules_count > 0
  44. target = Tracker.new(:name => 'Target', :default_status_id => 1)
  45. assert target.save
  46. target.copy_workflow_rules(source)
  47. target.reload
  48. assert_equal rules_count, target.workflow_rules.size
  49. end
  50. def test_issue_statuses
  51. tracker = Tracker.find(1)
  52. WorkflowTransition.delete_all
  53. WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 2, :new_status_id => 3)
  54. WorkflowTransition.create!(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 5)
  55. assert_kind_of Array, tracker.issue_statuses
  56. assert_kind_of IssueStatus, tracker.issue_statuses.first
  57. assert_equal [2, 3, 5], Tracker.find(1).issue_statuses.collect(&:id)
  58. end
  59. def test_issue_statuses_empty
  60. WorkflowTransition.where(:tracker_id => 1).delete_all
  61. assert_equal [], Tracker.find(1).issue_statuses
  62. end
  63. def test_issue_statuses_should_be_empty_for_new_record
  64. assert_equal [], Tracker.new.issue_statuses
  65. end
  66. def test_core_fields_should_be_enabled_by_default
  67. tracker = Tracker.new
  68. assert_equal Tracker::CORE_FIELDS, tracker.core_fields
  69. assert_equal [], tracker.disabled_core_fields
  70. end
  71. def test_core_fields
  72. tracker = Tracker.new
  73. tracker.core_fields = %w(assigned_to_id due_date)
  74. assert_equal %w(assigned_to_id due_date), tracker.core_fields
  75. assert_equal Tracker::CORE_FIELDS - %w(assigned_to_id due_date), tracker.disabled_core_fields
  76. end
  77. def test_core_fields_should_return_fields_enabled_for_any_tracker
  78. trackers = []
  79. trackers << Tracker.new(:core_fields => %w(assigned_to_id due_date))
  80. trackers << Tracker.new(:core_fields => %w(assigned_to_id done_ratio))
  81. trackers << Tracker.new(:core_fields => [])
  82. assert_equal %w(assigned_to_id due_date done_ratio), Tracker.core_fields(trackers)
  83. assert_equal Tracker::CORE_FIELDS - %w(assigned_to_id due_date done_ratio), Tracker.disabled_core_fields(trackers)
  84. end
  85. def test_core_fields_should_return_all_fields_for_an_empty_argument
  86. assert_equal Tracker::CORE_FIELDS, Tracker.core_fields([])
  87. assert_equal [], Tracker.disabled_core_fields([])
  88. end
  89. def test_sort_should_sort_by_position
  90. a = Tracker.new(:name => 'Tracker A', :position => 2)
  91. b = Tracker.new(:name => 'Tracker B', :position => 1)
  92. assert_equal [b, a], [a, b].sort
  93. end
  94. def test_destroying_a_tracker_without_issues_should_not_raise_an_error
  95. tracker = Tracker.find(1)
  96. Issue.where(:tracker_id => tracker.id).delete_all
  97. assert_difference 'Tracker.count', -1 do
  98. assert_nothing_raised do
  99. tracker.destroy
  100. end
  101. end
  102. end
  103. def test_destroying_a_tracker_with_issues_should_raise_an_error
  104. tracker = Tracker.find(1)
  105. assert_no_difference 'Tracker.count' do
  106. assert_raise StandardError do
  107. tracker.destroy
  108. end
  109. end
  110. end
  111. def test_tracker_should_have_description
  112. tracker = Tracker.find(1)
  113. assert tracker.respond_to?(:description)
  114. assert_equal tracker.description, "Description for Bug tracker"
  115. end
  116. end