@@ -1,258 +1,260 | |||
|
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 IssueSubtaskingTest < ActiveSupport::TestCase |
|
21 | 21 | fixtures :projects, :users, :roles, :members, :member_roles, |
|
22 | 22 | :trackers, :projects_trackers, |
|
23 | 23 | :issue_statuses, :issue_categories, :enumerations, |
|
24 | :issues | |
|
24 | :issues, | |
|
25 | :enabled_modules, | |
|
26 | :workflows | |
|
25 | 27 | |
|
26 | 28 | def test_leaf_planning_fields_should_be_editable |
|
27 | 29 | issue = Issue.generate! |
|
28 | 30 | user = User.find(1) |
|
29 | 31 | %w(priority_id done_ratio start_date due_date estimated_hours).each do |attribute| |
|
30 | 32 | assert issue.safe_attribute?(attribute, user) |
|
31 | 33 | end |
|
32 | 34 | end |
|
33 | 35 | |
|
34 | 36 | def test_parent_dates_should_be_read_only_with_parent_issue_dates_set_to_derived |
|
35 | 37 | with_settings :parent_issue_dates => 'derived' do |
|
36 | 38 | issue = Issue.generate_with_child! |
|
37 | 39 | user = User.find(1) |
|
38 | 40 | %w(start_date due_date).each do |attribute| |
|
39 | 41 | assert !issue.safe_attribute?(attribute, user) |
|
40 | 42 | end |
|
41 | 43 | end |
|
42 | 44 | end |
|
43 | 45 | |
|
44 | 46 | def test_parent_dates_should_be_lowest_start_and_highest_due_dates_with_parent_issue_dates_set_to_derived |
|
45 | 47 | with_settings :parent_issue_dates => 'derived' do |
|
46 | 48 | parent = Issue.generate! |
|
47 | 49 | parent.generate_child!(:start_date => '2010-01-25', :due_date => '2010-02-15') |
|
48 | 50 | parent.generate_child!( :due_date => '2010-02-13') |
|
49 | 51 | parent.generate_child!(:start_date => '2010-02-01', :due_date => '2010-02-22') |
|
50 | 52 | parent.reload |
|
51 | 53 | assert_equal Date.parse('2010-01-25'), parent.start_date |
|
52 | 54 | assert_equal Date.parse('2010-02-22'), parent.due_date |
|
53 | 55 | end |
|
54 | 56 | end |
|
55 | 57 | |
|
56 | 58 | def test_reschuling_a_parent_should_reschedule_subtasks_with_parent_issue_dates_set_to_derived |
|
57 | 59 | with_settings :parent_issue_dates => 'derived' do |
|
58 | 60 | parent = Issue.generate! |
|
59 | 61 | c1 = parent.generate_child!(:start_date => '2010-05-12', :due_date => '2010-05-18') |
|
60 | 62 | c2 = parent.generate_child!(:start_date => '2010-06-03', :due_date => '2010-06-10') |
|
61 | 63 | parent.reload.reschedule_on!(Date.parse('2010-06-02')) |
|
62 | 64 | c1.reload |
|
63 | 65 | assert_equal [Date.parse('2010-06-02'), Date.parse('2010-06-08')], [c1.start_date, c1.due_date] |
|
64 | 66 | c2.reload |
|
65 | 67 | assert_equal [Date.parse('2010-06-03'), Date.parse('2010-06-10')], [c2.start_date, c2.due_date] # no change |
|
66 | 68 | parent.reload |
|
67 | 69 | assert_equal [Date.parse('2010-06-02'), Date.parse('2010-06-10')], [parent.start_date, parent.due_date] |
|
68 | 70 | end |
|
69 | 71 | end |
|
70 | 72 | |
|
71 | 73 | def test_parent_priority_should_be_read_only_with_parent_issue_priority_set_to_derived |
|
72 | 74 | with_settings :parent_issue_priority => 'derived' do |
|
73 | 75 | issue = Issue.generate_with_child! |
|
74 | 76 | user = User.find(1) |
|
75 | 77 | assert !issue.safe_attribute?('priority_id', user) |
|
76 | 78 | end |
|
77 | 79 | end |
|
78 | 80 | |
|
79 | 81 | def test_parent_priority_should_be_the_highest_child_priority |
|
80 | 82 | with_settings :parent_issue_priority => 'derived' do |
|
81 | 83 | parent = Issue.generate!(:priority => IssuePriority.find_by_name('Normal')) |
|
82 | 84 | # Create children |
|
83 | 85 | child1 = parent.generate_child!(:priority => IssuePriority.find_by_name('High')) |
|
84 | 86 | assert_equal 'High', parent.reload.priority.name |
|
85 | 87 | child2 = child1.generate_child!(:priority => IssuePriority.find_by_name('Immediate')) |
|
86 | 88 | assert_equal 'Immediate', child1.reload.priority.name |
|
87 | 89 | assert_equal 'Immediate', parent.reload.priority.name |
|
88 | 90 | child3 = parent.generate_child!(:priority => IssuePriority.find_by_name('Low')) |
|
89 | 91 | assert_equal 'Immediate', parent.reload.priority.name |
|
90 | 92 | # Destroy a child |
|
91 | 93 | child1.destroy |
|
92 | 94 | assert_equal 'Low', parent.reload.priority.name |
|
93 | 95 | # Update a child |
|
94 | 96 | child3.reload.priority = IssuePriority.find_by_name('Normal') |
|
95 | 97 | child3.save! |
|
96 | 98 | assert_equal 'Normal', parent.reload.priority.name |
|
97 | 99 | end |
|
98 | 100 | end |
|
99 | 101 | |
|
100 | 102 | def test_parent_done_ratio_should_be_read_only_with_parent_issue_done_ratio_set_to_derived |
|
101 | 103 | with_settings :parent_issue_done_ratio => 'derived' do |
|
102 | 104 | issue = Issue.generate_with_child! |
|
103 | 105 | user = User.find(1) |
|
104 | 106 | assert !issue.safe_attribute?('done_ratio', user) |
|
105 | 107 | end |
|
106 | 108 | end |
|
107 | 109 | |
|
108 | 110 | def test_parent_done_ratio_should_be_average_done_ratio_of_leaves |
|
109 | 111 | with_settings :parent_issue_done_ratio => 'derived' do |
|
110 | 112 | parent = Issue.generate! |
|
111 | 113 | parent.generate_child!(:done_ratio => 20) |
|
112 | 114 | assert_equal 20, parent.reload.done_ratio |
|
113 | 115 | parent.generate_child!(:done_ratio => 70) |
|
114 | 116 | assert_equal 45, parent.reload.done_ratio |
|
115 | 117 | |
|
116 | 118 | child = parent.generate_child!(:done_ratio => 0) |
|
117 | 119 | assert_equal 30, parent.reload.done_ratio |
|
118 | 120 | |
|
119 | 121 | child.generate_child!(:done_ratio => 30) |
|
120 | 122 | assert_equal 30, child.reload.done_ratio |
|
121 | 123 | assert_equal 40, parent.reload.done_ratio |
|
122 | 124 | end |
|
123 | 125 | end |
|
124 | 126 | |
|
125 | 127 | def test_parent_done_ratio_should_be_weighted_by_estimated_times_if_any |
|
126 | 128 | with_settings :parent_issue_done_ratio => 'derived' do |
|
127 | 129 | parent = Issue.generate! |
|
128 | 130 | parent.generate_child!(:estimated_hours => 10, :done_ratio => 20) |
|
129 | 131 | assert_equal 20, parent.reload.done_ratio |
|
130 | 132 | parent.generate_child!(:estimated_hours => 20, :done_ratio => 50) |
|
131 | 133 | assert_equal (50 * 20 + 20 * 10) / 30, parent.reload.done_ratio |
|
132 | 134 | end |
|
133 | 135 | end |
|
134 | 136 | |
|
135 | 137 | def test_parent_done_ratio_with_child_estimate_to_0_should_reach_100 |
|
136 | 138 | with_settings :parent_issue_done_ratio => 'derived' do |
|
137 | 139 | parent = Issue.generate! |
|
138 | 140 | issue1 = parent.generate_child! |
|
139 | 141 | issue2 = parent.generate_child!(:estimated_hours => 0) |
|
140 | 142 | assert_equal 0, parent.reload.done_ratio |
|
141 | 143 | issue1.reload.close! |
|
142 | 144 | assert_equal 50, parent.reload.done_ratio |
|
143 | 145 | issue2.reload.close! |
|
144 | 146 | assert_equal 100, parent.reload.done_ratio |
|
145 | 147 | end |
|
146 | 148 | end |
|
147 | 149 | |
|
148 | 150 | def test_done_ratio_of_parent_with_a_child_without_estimated_time_should_not_exceed_100 |
|
149 | 151 | with_settings :parent_issue_done_ratio => 'derived' do |
|
150 | 152 | parent = Issue.generate! |
|
151 | 153 | parent.generate_child!(:estimated_hours => 40) |
|
152 | 154 | parent.generate_child!(:estimated_hours => 40) |
|
153 | 155 | parent.generate_child!(:estimated_hours => 20) |
|
154 | 156 | parent.generate_child! |
|
155 | 157 | parent.reload.children.each(&:close!) |
|
156 | 158 | assert_equal 100, parent.reload.done_ratio |
|
157 | 159 | end |
|
158 | 160 | end |
|
159 | 161 | |
|
160 | 162 | def test_done_ratio_of_parent_with_a_child_with_estimated_time_at_0_should_not_exceed_100 |
|
161 | 163 | with_settings :parent_issue_done_ratio => 'derived' do |
|
162 | 164 | parent = Issue.generate! |
|
163 | 165 | parent.generate_child!(:estimated_hours => 40) |
|
164 | 166 | parent.generate_child!(:estimated_hours => 40) |
|
165 | 167 | parent.generate_child!(:estimated_hours => 20) |
|
166 | 168 | parent.generate_child!(:estimated_hours => 0) |
|
167 | 169 | parent.reload.children.each(&:close!) |
|
168 | 170 | assert_equal 100, parent.reload.done_ratio |
|
169 | 171 | end |
|
170 | 172 | end |
|
171 | 173 | |
|
172 | 174 | def test_changing_parent_should_update_previous_parent_done_ratio |
|
173 | 175 | with_settings :parent_issue_done_ratio => 'derived' do |
|
174 | 176 | first_parent = Issue.generate! |
|
175 | 177 | second_parent = Issue.generate! |
|
176 | 178 | first_parent.generate_child!(:done_ratio => 40) |
|
177 | 179 | child = first_parent.generate_child!(:done_ratio => 20) |
|
178 | 180 | assert_equal 30, first_parent.reload.done_ratio |
|
179 | 181 | assert_equal 0, second_parent.reload.done_ratio |
|
180 | 182 | child.update_attributes(:parent_issue_id => second_parent.id) |
|
181 | 183 | assert_equal 40, first_parent.reload.done_ratio |
|
182 | 184 | assert_equal 20, second_parent.reload.done_ratio |
|
183 | 185 | end |
|
184 | 186 | end |
|
185 | 187 | |
|
186 | 188 | def test_parent_dates_should_be_editable_with_parent_issue_dates_set_to_independent |
|
187 | 189 | with_settings :parent_issue_dates => 'independent' do |
|
188 | 190 | issue = Issue.generate_with_child! |
|
189 | 191 | user = User.find(1) |
|
190 | 192 | %w(start_date due_date).each do |attribute| |
|
191 | 193 | assert issue.safe_attribute?(attribute, user) |
|
192 | 194 | end |
|
193 | 195 | end |
|
194 | 196 | end |
|
195 | 197 | |
|
196 | 198 | def test_parent_dates_should_not_be_updated_with_parent_issue_dates_set_to_independent |
|
197 | 199 | with_settings :parent_issue_dates => 'independent' do |
|
198 | 200 | parent = Issue.generate!(:start_date => '2015-07-01', :due_date => '2015-08-01') |
|
199 | 201 | parent.generate_child!(:start_date => '2015-06-01', :due_date => '2015-09-01') |
|
200 | 202 | parent.reload |
|
201 | 203 | assert_equal Date.parse('2015-07-01'), parent.start_date |
|
202 | 204 | assert_equal Date.parse('2015-08-01'), parent.due_date |
|
203 | 205 | end |
|
204 | 206 | end |
|
205 | 207 | |
|
206 | 208 | def test_reschuling_a_parent_should_not_reschedule_subtasks_with_parent_issue_dates_set_to_independent |
|
207 | 209 | with_settings :parent_issue_dates => 'independent' do |
|
208 | 210 | parent = Issue.generate!(:start_date => '2010-05-01', :due_date => '2010-05-20') |
|
209 | 211 | c1 = parent.generate_child!(:start_date => '2010-05-12', :due_date => '2010-05-18') |
|
210 | 212 | parent.reload.reschedule_on!(Date.parse('2010-06-01')) |
|
211 | 213 | assert_equal Date.parse('2010-06-01'), parent.reload.start_date |
|
212 | 214 | c1.reload |
|
213 | 215 | assert_equal [Date.parse('2010-05-12'), Date.parse('2010-05-18')], [c1.start_date, c1.due_date] |
|
214 | 216 | end |
|
215 | 217 | end |
|
216 | 218 | |
|
217 | 219 | def test_parent_priority_should_be_editable_with_parent_issue_priority_set_to_independent |
|
218 | 220 | with_settings :parent_issue_priority => 'independent' do |
|
219 | 221 | issue = Issue.generate_with_child! |
|
220 | 222 | user = User.find(1) |
|
221 | 223 | assert issue.safe_attribute?('priority_id', user) |
|
222 | 224 | end |
|
223 | 225 | end |
|
224 | 226 | |
|
225 | 227 | def test_parent_priority_should_not_be_updated_with_parent_issue_priority_set_to_independent |
|
226 | 228 | with_settings :parent_issue_priority => 'independent' do |
|
227 | 229 | parent = Issue.generate!(:priority => IssuePriority.find_by_name('Normal')) |
|
228 | 230 | child1 = parent.generate_child!(:priority => IssuePriority.find_by_name('High')) |
|
229 | 231 | assert_equal 'Normal', parent.reload.priority.name |
|
230 | 232 | end |
|
231 | 233 | end |
|
232 | 234 | |
|
233 | 235 | def test_parent_done_ratio_should_be_editable_with_parent_issue_done_ratio_set_to_independent |
|
234 | 236 | with_settings :parent_issue_done_ratio => 'independent' do |
|
235 | 237 | issue = Issue.generate_with_child! |
|
236 | 238 | user = User.find(1) |
|
237 | 239 | assert issue.safe_attribute?('done_ratio', user) |
|
238 | 240 | end |
|
239 | 241 | end |
|
240 | 242 | |
|
241 | 243 | def test_parent_done_ratio_should_not_be_updated_with_parent_issue_done_ratio_set_to_independent |
|
242 | 244 | with_settings :parent_issue_done_ratio => 'independent' do |
|
243 | 245 | parent = Issue.generate!(:done_ratio => 0) |
|
244 | 246 | child1 = parent.generate_child!(:done_ratio => 10) |
|
245 | 247 | assert_equal 0, parent.reload.done_ratio |
|
246 | 248 | end |
|
247 | 249 | end |
|
248 | 250 | |
|
249 | 251 | def test_parent_total_estimated_hours_should_be_sum_of_descendants |
|
250 | 252 | parent = Issue.generate! |
|
251 | 253 | parent.generate_child!(:estimated_hours => nil) |
|
252 | 254 | assert_equal 0, parent.reload.total_estimated_hours |
|
253 | 255 | parent.generate_child!(:estimated_hours => 5) |
|
254 | 256 | assert_equal 5, parent.reload.total_estimated_hours |
|
255 | 257 | parent.generate_child!(:estimated_hours => 7) |
|
256 | 258 | assert_equal 12, parent.reload.total_estimated_hours |
|
257 | 259 | end |
|
258 | 260 | end |
General Comments 0
You need to be logged in to leave comments.
Login now