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