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

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