Mercurial > hg > soundsoftware-site
comparison test/unit/issue_priority_test.rb @ 1337:077b8890835a cannam
Merge from live branch
author | Chris Cannam |
---|---|
date | Thu, 20 Jun 2013 13:14:02 +0100 |
parents | 433d4f72a19b |
children | 622f24f53b42 |
comparison
equal
deleted
inserted
replaced
1304:6137548ba453 | 1337:077b8890835a |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2011 Jean-Philippe Lang | 2 # Copyright (C) 2006-2012 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. |
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 | |
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 | |
23 def test_should_be_an_enumeration | 36 def test_should_be_an_enumeration |
24 assert IssuePriority.ancestors.include?(Enumeration) | 37 assert IssuePriority.ancestors.include?(Enumeration) |
25 end | 38 end |
26 | 39 |
27 def test_objects_count | 40 def test_objects_count |
32 end | 45 end |
33 | 46 |
34 def test_option_name | 47 def test_option_name |
35 assert_equal :enumeration_issue_priorities, IssuePriority.new.option_name | 48 assert_equal :enumeration_issue_priorities, IssuePriority.new.option_name |
36 end | 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 | |
37 end | 106 end |
38 |