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.

issue_priority_test.rb 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2019 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 IssuePriorityTest < ActiveSupport::TestCase
  20. fixtures :enumerations, :issues
  21. def setup
  22. User.current = nil
  23. end
  24. def test_named_scope
  25. assert_equal Enumeration.find_by_name('Normal'), Enumeration.named('normal').first
  26. end
  27. def test_default_should_return_the_default_priority
  28. assert_equal Enumeration.find_by_name('Normal'), IssuePriority.default
  29. end
  30. def test_default_should_return_nil_when_no_default_priority
  31. IssuePriority.update_all :is_default => false
  32. assert_nil IssuePriority.default
  33. end
  34. def test_should_be_an_enumeration
  35. assert IssuePriority.ancestors.include?(Enumeration)
  36. end
  37. def test_objects_count
  38. # low priority
  39. assert_equal 6, IssuePriority.find(4).objects_count
  40. # urgent
  41. assert_equal 0, IssuePriority.find(7).objects_count
  42. end
  43. def test_option_name
  44. assert_equal :enumeration_issue_priorities, IssuePriority.new.option_name
  45. end
  46. def test_should_be_created_at_last_position
  47. IssuePriority.delete_all
  48. priorities = [1, 2, 3].map {|i| IssuePriority.create!(:name => "P#{i}")}
  49. assert_equal [1, 2, 3], priorities.map(&:position)
  50. end
  51. def test_clear_position_names_should_set_position_names_to_nil
  52. IssuePriority.clear_position_names
  53. assert IssuePriority.all.all? {|priority| priority.position_name.nil?}
  54. end
  55. def test_compute_position_names_with_default_priority
  56. IssuePriority.clear_position_names
  57. IssuePriority.compute_position_names
  58. assert_equal %w(lowest default high3 high2 highest), IssuePriority.active.to_a.sort.map(&:position_name)
  59. end
  60. def test_compute_position_names_without_default_priority_should_split_priorities
  61. IssuePriority.clear_position_names
  62. IssuePriority.update_all :is_default => false
  63. IssuePriority.compute_position_names
  64. assert_equal %w(lowest low2 default high2 highest), IssuePriority.active.to_a.sort.map(&:position_name)
  65. end
  66. def test_adding_a_priority_should_update_position_names
  67. priority = IssuePriority.create!(:name => 'New')
  68. assert_equal %w(lowest default high4 high3 high2 highest), IssuePriority.active.to_a.sort.map(&:position_name)
  69. end
  70. def test_moving_a_priority_should_update_position_names
  71. prio = IssuePriority.first
  72. prio.position = IssuePriority.count
  73. prio.save!
  74. prio.reload
  75. assert_equal 'highest', prio.position_name
  76. end
  77. def test_deactivating_a_priority_should_update_position_names
  78. prio = IssuePriority.active.order(:position).last
  79. prio.active = false
  80. prio.save
  81. assert_equal 'highest', IssuePriority.active.order(:position).last.position_name
  82. end
  83. def test_changing_default_priority_should_update_position_names
  84. prio = IssuePriority.first
  85. prio.is_default = true
  86. prio.save
  87. assert_equal %w(default high4 high3 high2 highest), IssuePriority.active.to_a.sort.map(&:position_name)
  88. end
  89. def test_destroying_a_priority_should_update_position_names
  90. IssuePriority.find_by_position_name('highest').destroy
  91. assert_equal %w(lowest default high2 highest), IssuePriority.active.to_a.sort.map(&:position_name)
  92. end
  93. end