comparison .svn/pristine/65/65b88641ff8e4579cbf40b69a6bf7f5392a27740.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
comparison
equal deleted inserted replaced
1297:0a574315af3e 1298:4f746d8966dd
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 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
18 require File.expand_path('../../test_helper', __FILE__)
19
20 class IssuePriorityTest < ActiveSupport::TestCase
21 fixtures :enumerations, :issues
22
23 def test_named_scope
24 assert_equal Enumeration.find_by_name('Normal'), Enumeration.named('normal').first
25 end
26
27 def test_default_should_return_the_default_priority
28 assert_equal Enumeration.find_by_name('Normal'), IssuePriority.default
29 end
30
31 def test_default_should_return_nil_when_no_default_priority
32 IssuePriority.update_all :is_default => false
33 assert_nil IssuePriority.default
34 end
35
36 def test_should_be_an_enumeration
37 assert IssuePriority.ancestors.include?(Enumeration)
38 end
39
40 def test_objects_count
41 # low priority
42 assert_equal 6, IssuePriority.find(4).objects_count
43 # urgent
44 assert_equal 0, IssuePriority.find(7).objects_count
45 end
46
47 def test_option_name
48 assert_equal :enumeration_issue_priorities, IssuePriority.new.option_name
49 end
50
51 def test_should_be_created_at_last_position
52 IssuePriority.delete_all
53
54 priorities = [1, 2, 3].map {|i| IssuePriority.create!(:name => "P#{i}")}
55 assert_equal [1, 2, 3], priorities.map(&:position)
56 end
57
58 def test_reset_positions_in_list_should_set_sequential_positions
59 IssuePriority.delete_all
60
61 priorities = [1, 2, 3].map {|i| IssuePriority.create!(:name => "P#{i}")}
62 priorities[0].update_attribute :position, 4
63 priorities[1].update_attribute :position, 2
64 priorities[2].update_attribute :position, 7
65 assert_equal [4, 2, 7], priorities.map(&:reload).map(&:position)
66
67 priorities[0].reset_positions_in_list
68 assert_equal [2, 1, 3], priorities.map(&:reload).map(&:position)
69 end
70
71 def test_moving_in_list_should_reset_positions
72 priority = IssuePriority.first
73 priority.expects(:reset_positions_in_list).once
74 priority.move_to = 'higher'
75 end
76
77 def test_clear_position_names_should_set_position_names_to_nil
78 IssuePriority.clear_position_names
79 assert IssuePriority.all.all? {|priority| priority.position_name.nil?}
80 end
81
82 def test_compute_position_names_with_default_priority
83 IssuePriority.clear_position_names
84
85 IssuePriority.compute_position_names
86 assert_equal %w(lowest default high3 high2 highest), IssuePriority.active.all.sort.map(&:position_name)
87 end
88
89 def test_compute_position_names_without_default_priority_should_split_priorities
90 IssuePriority.clear_position_names
91 IssuePriority.update_all :is_default => false
92
93 IssuePriority.compute_position_names
94 assert_equal %w(lowest low2 default high2 highest), IssuePriority.active.all.sort.map(&:position_name)
95 end
96
97 def test_adding_a_priority_should_update_position_names
98 priority = IssuePriority.create!(:name => 'New')
99 assert_equal %w(lowest default high4 high3 high2 highest), IssuePriority.active.all.sort.map(&:position_name)
100 end
101
102 def test_destroying_a_priority_should_update_position_names
103 IssuePriority.find_by_position_name('highest').destroy
104 assert_equal %w(lowest default high2 highest), IssuePriority.active.all.sort.map(&:position_name)
105 end
106 end