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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2008 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
  20. def test_sorted_scope
  21. assert_equal Tracker.all.sort, Tracker.sorted.all
  22. end
  23. def test_named_scope
  24. assert_equal Tracker.find_by_name('Feature'), Tracker.named('feature').first
  25. end
  26. def test_copy_workflows
  27. source = Tracker.find(1)
  28. assert_equal 89, source.workflow_rules.size
  29. target = Tracker.new(:name => 'Target')
  30. assert target.save
  31. target.workflow_rules.copy(source)
  32. target.reload
  33. assert_equal 89, target.workflow_rules.size
  34. end
  35. def test_issue_statuses
  36. tracker = Tracker.find(1)
  37. WorkflowTransition.delete_all
  38. WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 2, :new_status_id => 3)
  39. WorkflowTransition.create!(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 5)
  40. assert_kind_of Array, tracker.issue_statuses
  41. assert_kind_of IssueStatus, tracker.issue_statuses.first
  42. assert_equal [2, 3, 5], Tracker.find(1).issue_statuses.collect(&:id)
  43. end
  44. def test_issue_statuses_empty
  45. WorkflowTransition.delete_all("tracker_id = 1")
  46. assert_equal [], Tracker.find(1).issue_statuses
  47. end
  48. def test_issue_statuses_should_be_empty_for_new_record
  49. assert_equal [], Tracker.new.issue_statuses
  50. end
  51. def test_core_fields_should_be_enabled_by_default
  52. tracker = Tracker.new
  53. assert_equal Tracker::CORE_FIELDS, tracker.core_fields
  54. assert_equal [], tracker.disabled_core_fields
  55. end
  56. def test_core_fields
  57. tracker = Tracker.new
  58. tracker.core_fields = %w(assigned_to_id due_date)
  59. assert_equal %w(assigned_to_id due_date), tracker.core_fields
  60. assert_equal Tracker::CORE_FIELDS - %w(assigned_to_id due_date), tracker.disabled_core_fields
  61. end
  62. def test_core_fields_should_return_fields_enabled_for_any_tracker
  63. trackers = []
  64. trackers << Tracker.new(:core_fields => %w(assigned_to_id due_date))
  65. trackers << Tracker.new(:core_fields => %w(assigned_to_id done_ratio))
  66. trackers << Tracker.new(:core_fields => [])
  67. assert_equal %w(assigned_to_id due_date done_ratio), Tracker.core_fields(trackers)
  68. assert_equal Tracker::CORE_FIELDS - %w(assigned_to_id due_date done_ratio), Tracker.disabled_core_fields(trackers)
  69. end
  70. def test_core_fields_should_return_all_fields_for_an_empty_argument
  71. assert_equal Tracker::CORE_FIELDS, Tracker.core_fields([])
  72. assert_equal [], Tracker.disabled_core_fields([])
  73. end
  74. def test_sort_should_sort_by_position
  75. a = Tracker.new(:name => 'Tracker A', :position => 2)
  76. b = Tracker.new(:name => 'Tracker B', :position => 1)
  77. assert_equal [b, a], [a, b].sort
  78. end
  79. def test_destroying_a_tracker_without_issues_should_not_raise_an_error
  80. tracker = Tracker.find(1)
  81. Issue.delete_all :tracker_id => tracker.id
  82. assert_difference 'Tracker.count', -1 do
  83. assert_nothing_raised do
  84. tracker.destroy
  85. end
  86. end
  87. end
  88. def test_destroying_a_tracker_with_issues_should_raise_an_error
  89. tracker = Tracker.find(1)
  90. assert_no_difference 'Tracker.count' do
  91. assert_raise Exception do
  92. tracker.destroy
  93. end
  94. end
  95. end
  96. end