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

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