##// END OF EJS Templates
IssuePriority.position_name not recalculated every time it should (#21504)....
Jean-Philippe Lang -
r14607:ff7938cff203
parent child
Show More
@@ -1,106 +1,120
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2015 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class IssuePriorityTest < ActiveSupport::TestCase
21 21 fixtures :enumerations, :issues
22 22
23 23 def test_named_scope
24 24 assert_equal Enumeration.find_by_name('Normal'), Enumeration.named('normal').first
25 25 end
26 26
27 27 def test_default_should_return_the_default_priority
28 28 assert_equal Enumeration.find_by_name('Normal'), IssuePriority.default
29 29 end
30 30
31 31 def test_default_should_return_nil_when_no_default_priority
32 32 IssuePriority.update_all :is_default => false
33 33 assert_nil IssuePriority.default
34 34 end
35 35
36 36 def test_should_be_an_enumeration
37 37 assert IssuePriority.ancestors.include?(Enumeration)
38 38 end
39 39
40 40 def test_objects_count
41 41 # low priority
42 42 assert_equal 6, IssuePriority.find(4).objects_count
43 43 # urgent
44 44 assert_equal 0, IssuePriority.find(7).objects_count
45 45 end
46 46
47 47 def test_option_name
48 48 assert_equal :enumeration_issue_priorities, IssuePriority.new.option_name
49 49 end
50 50
51 51 def test_should_be_created_at_last_position
52 52 IssuePriority.delete_all
53 53
54 54 priorities = [1, 2, 3].map {|i| IssuePriority.create!(:name => "P#{i}")}
55 55 assert_equal [1, 2, 3], priorities.map(&:position)
56 56 end
57 57
58 58 def test_reset_positions_in_list_should_set_sequential_positions
59 59 IssuePriority.delete_all
60 60
61 61 priorities = [1, 2, 3].map {|i| IssuePriority.create!(:name => "P#{i}")}
62 62 priorities[0].update_attribute :position, 4
63 63 priorities[1].update_attribute :position, 2
64 64 priorities[2].update_attribute :position, 7
65 65 assert_equal [4, 2, 7], priorities.map(&:reload).map(&:position)
66 66
67 67 priorities[0].reset_positions_in_list
68 68 assert_equal [2, 1, 3], priorities.map(&:reload).map(&:position)
69 69 end
70 70
71 71 def test_moving_in_list_should_reset_positions
72 72 priority = IssuePriority.first
73 73 priority.expects(:reset_positions_in_list).once
74 74 priority.move_to = 'higher'
75 75 end
76 76
77 77 def test_clear_position_names_should_set_position_names_to_nil
78 78 IssuePriority.clear_position_names
79 79 assert IssuePriority.all.all? {|priority| priority.position_name.nil?}
80 80 end
81 81
82 82 def test_compute_position_names_with_default_priority
83 83 IssuePriority.clear_position_names
84 84
85 85 IssuePriority.compute_position_names
86 86 assert_equal %w(lowest default high3 high2 highest), IssuePriority.active.to_a.sort.map(&:position_name)
87 87 end
88 88
89 89 def test_compute_position_names_without_default_priority_should_split_priorities
90 90 IssuePriority.clear_position_names
91 91 IssuePriority.update_all :is_default => false
92 92
93 93 IssuePriority.compute_position_names
94 94 assert_equal %w(lowest low2 default high2 highest), IssuePriority.active.to_a.sort.map(&:position_name)
95 95 end
96 96
97 97 def test_adding_a_priority_should_update_position_names
98 98 priority = IssuePriority.create!(:name => 'New')
99 99 assert_equal %w(lowest default high4 high3 high2 highest), IssuePriority.active.to_a.sort.map(&:position_name)
100 100 end
101 101
102 def test_moving_a_priority_should_update_position_names
103 prio = IssuePriority.first
104 prio.move_to = 'lowest'
105 prio.reload
106 assert_equal 'highest', prio.position_name
107 end
108
109 def test_deactivating_a_priority_should_update_position_names
110 prio = IssuePriority.active.order(:position).last
111 prio.active = false
112 prio.save
113 assert_equal 'highest', IssuePriority.active.order(:position).last.position_name
114 end
115
102 116 def test_destroying_a_priority_should_update_position_names
103 117 IssuePriority.find_by_position_name('highest').destroy
104 118 assert_equal %w(lowest default high2 highest), IssuePriority.active.to_a.sort.map(&:position_name)
105 119 end
106 120 end
General Comments 0
You need to be logged in to leave comments. Login now