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.4KB

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