@@ -179,3 +179,16 module ObjectHelpers | |||||
179 | changeset |
|
179 | changeset | |
180 | end |
|
180 | end | |
181 | end |
|
181 | end | |
|
182 | ||||
|
183 | module IssueObjectHelpers | |||
|
184 | def close! | |||
|
185 | self.status = IssueStatus.where(:is_closed => true).first | |||
|
186 | save! | |||
|
187 | end | |||
|
188 | ||||
|
189 | def generate_child!(attributes={}) | |||
|
190 | Issue.generate!(attributes.merge(:parent_issue_id => self.id)) | |||
|
191 | end | |||
|
192 | end | |||
|
193 | ||||
|
194 | Issue.send :include, IssueObjectHelpers |
@@ -43,7 +43,7 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
43 | def test_create_child_issue |
|
43 | def test_create_child_issue | |
44 | lft = new_issue_lft |
|
44 | lft = new_issue_lft | |
45 | parent = Issue.generate! |
|
45 | parent = Issue.generate! | |
46 | child = Issue.generate!(:parent_issue_id => parent.id) |
|
46 | child = parent.generate_child! | |
47 | parent.reload |
|
47 | parent.reload | |
48 | child.reload |
|
48 | child.reload | |
49 | assert_equal [parent.id, nil, lft, lft + 3], [parent.root_id, parent.parent_id, parent.lft, parent.rgt] |
|
49 | assert_equal [parent.id, nil, lft, lft + 3], [parent.root_id, parent.parent_id, parent.lft, parent.rgt] | |
@@ -70,7 +70,7 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
70 | lft = new_issue_lft |
|
70 | lft = new_issue_lft | |
71 | parent1 = Issue.generate! |
|
71 | parent1 = Issue.generate! | |
72 | parent2 = Issue.generate! |
|
72 | parent2 = Issue.generate! | |
73 | child = Issue.generate!(:parent_issue_id => parent1.id) |
|
73 | child = parent1.generate_child! | |
74 | parent2.parent_issue_id = parent1.id |
|
74 | parent2.parent_issue_id = parent1.id | |
75 | parent2.save! |
|
75 | parent2.save! | |
76 | child.reload |
|
76 | child.reload | |
@@ -86,7 +86,7 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
86 | parent1 = Issue.generate! |
|
86 | parent1 = Issue.generate! | |
87 | lft2 = new_issue_lft |
|
87 | lft2 = new_issue_lft | |
88 | parent2 = Issue.generate! |
|
88 | parent2 = Issue.generate! | |
89 | child = Issue.generate!(:parent_issue_id => parent1.id) |
|
89 | child = parent1.generate_child! | |
90 | child.parent_issue_id = nil |
|
90 | child.parent_issue_id = nil | |
91 | child.save! |
|
91 | child.save! | |
92 | child.reload |
|
92 | child.reload | |
@@ -102,7 +102,7 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
102 | parent1 = Issue.generate! |
|
102 | parent1 = Issue.generate! | |
103 | lft2 = new_issue_lft |
|
103 | lft2 = new_issue_lft | |
104 | parent2 = Issue.generate! |
|
104 | parent2 = Issue.generate! | |
105 | child = Issue.generate!(:parent_issue_id => parent1.id) |
|
105 | child = parent1.generate_child! | |
106 | child.parent_issue_id = parent2.id |
|
106 | child.parent_issue_id = parent2.id | |
107 | child.save! |
|
107 | child.save! | |
108 | child.reload |
|
108 | child.reload | |
@@ -118,8 +118,8 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
118 | parent1 = Issue.generate! |
|
118 | parent1 = Issue.generate! | |
119 | lft2 = new_issue_lft |
|
119 | lft2 = new_issue_lft | |
120 | parent2 = Issue.generate! |
|
120 | parent2 = Issue.generate! | |
121 | child = Issue.generate!(:parent_issue_id => parent1.id) |
|
121 | child = parent1.generate_child! | |
122 |
grandchild = |
|
122 | grandchild = child.generate_child! | |
123 | parent1.reload |
|
123 | parent1.reload | |
124 | parent2.reload |
|
124 | parent2.reload | |
125 | child.reload |
|
125 | child.reload | |
@@ -143,8 +143,8 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
143 | def test_move_a_child_with_descendants_to_another_project |
|
143 | def test_move_a_child_with_descendants_to_another_project | |
144 | lft1 = new_issue_lft |
|
144 | lft1 = new_issue_lft | |
145 | parent1 = Issue.generate! |
|
145 | parent1 = Issue.generate! | |
146 | child = Issue.generate!(:parent_issue_id => parent1.id) |
|
146 | child = parent1.generate_child! | |
147 |
grandchild = |
|
147 | grandchild = child.generate_child! | |
148 | child.reload |
|
148 | child.reload | |
149 | child.project = Project.find(2) |
|
149 | child.project = Project.find(2) | |
150 | assert child.save |
|
150 | assert child.save | |
@@ -159,8 +159,8 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
159 | def test_moving_an_issue_to_a_descendant_should_not_validate |
|
159 | def test_moving_an_issue_to_a_descendant_should_not_validate | |
160 | parent1 = Issue.generate! |
|
160 | parent1 = Issue.generate! | |
161 | parent2 = Issue.generate! |
|
161 | parent2 = Issue.generate! | |
162 | child = Issue.generate!(:parent_issue_id => parent1.id) |
|
162 | child = parent1.generate_child! | |
163 |
grandchild = |
|
163 | grandchild = child.generate_child! | |
164 |
|
164 | |||
165 | child.reload |
|
165 | child.reload | |
166 | child.parent_issue_id = grandchild.id |
|
166 | child.parent_issue_id = grandchild.id | |
@@ -207,8 +207,8 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
207 | lft1 = new_issue_lft |
|
207 | lft1 = new_issue_lft | |
208 | issue1 = Issue.generate! |
|
208 | issue1 = Issue.generate! | |
209 | issue2 = Issue.generate! |
|
209 | issue2 = Issue.generate! | |
210 | issue3 = Issue.generate!(:parent_issue_id => issue2.id) |
|
210 | issue3 = issue2.generate_child! | |
211 | issue4 = Issue.generate!(:parent_issue_id => issue1.id) |
|
211 | issue4 = issue1.generate_child! | |
212 | issue3.init_journal(User.find(2)) |
|
212 | issue3.init_journal(User.find(2)) | |
213 | issue3.subject = 'child with journal' |
|
213 | issue3.subject = 'child with journal' | |
214 | issue3.save! |
|
214 | issue3.save! | |
@@ -230,8 +230,8 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
230 | def test_destroy_child_should_update_parent |
|
230 | def test_destroy_child_should_update_parent | |
231 | lft1 = new_issue_lft |
|
231 | lft1 = new_issue_lft | |
232 | issue = Issue.generate! |
|
232 | issue = Issue.generate! | |
233 | child1 = Issue.generate!(:parent_issue_id => issue.id) |
|
233 | child1 = issue.generate_child! | |
234 | child2 = Issue.generate!(:parent_issue_id => issue.id) |
|
234 | child2 = issue.generate_child! | |
235 | issue.reload |
|
235 | issue.reload | |
236 | assert_equal [issue.id, lft1, lft1 + 5], [issue.root_id, issue.lft, issue.rgt] |
|
236 | assert_equal [issue.id, lft1, lft1 + 5], [issue.root_id, issue.lft, issue.rgt] | |
237 | child2.reload.destroy |
|
237 | child2.reload.destroy | |
@@ -241,8 +241,8 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
241 |
|
241 | |||
242 | def test_destroy_parent_issue_updated_during_children_destroy |
|
242 | def test_destroy_parent_issue_updated_during_children_destroy | |
243 | parent = Issue.generate! |
|
243 | parent = Issue.generate! | |
244 |
|
|
244 | parent.generate_child!(:start_date => Date.today) | |
245 |
|
|
245 | parent.generate_child!(:start_date => 2.days.from_now) | |
246 |
|
246 | |||
247 | assert_difference 'Issue.count', -3 do |
|
247 | assert_difference 'Issue.count', -3 do | |
248 | Issue.find(parent.id).destroy |
|
248 | Issue.find(parent.id).destroy | |
@@ -250,9 +250,9 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
250 | end |
|
250 | end | |
251 |
|
251 | |||
252 | def test_destroy_child_issue_with_children |
|
252 | def test_destroy_child_issue_with_children | |
253 | root = Issue.create!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'root') |
|
253 | root = Issue.generate! | |
254 | child = Issue.create!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => root.id) |
|
254 | child = root.generate_child! | |
255 | leaf = Issue.create!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'leaf', :parent_issue_id => child.id) |
|
255 | leaf = child.generate_child! | |
256 | leaf.init_journal(User.find(2)) |
|
256 | leaf.init_journal(User.find(2)) | |
257 | leaf.subject = 'leaf with journal' |
|
257 | leaf.subject = 'leaf with journal' | |
258 | leaf.save! |
|
258 | leaf.save! | |
@@ -272,10 +272,10 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
272 | def test_destroy_issue_with_grand_child |
|
272 | def test_destroy_issue_with_grand_child | |
273 | lft1 = new_issue_lft |
|
273 | lft1 = new_issue_lft | |
274 | parent = Issue.generate! |
|
274 | parent = Issue.generate! | |
275 | issue = Issue.generate!(:parent_issue_id => parent.id) |
|
275 | issue = parent.generate_child! | |
276 | child = Issue.generate!(:parent_issue_id => issue.id) |
|
276 | child = issue.generate_child! | |
277 |
grandchild1 = |
|
277 | grandchild1 = child.generate_child! | |
278 |
grandchild2 = |
|
278 | grandchild2 = child.generate_child! | |
279 | assert_difference 'Issue.count', -4 do |
|
279 | assert_difference 'Issue.count', -4 do | |
280 | Issue.find(issue.id).destroy |
|
280 | Issue.find(issue.id).destroy | |
281 | parent.reload |
|
281 | parent.reload | |
@@ -286,12 +286,12 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
286 | def test_parent_priority_should_be_the_highest_child_priority |
|
286 | def test_parent_priority_should_be_the_highest_child_priority | |
287 | parent = Issue.generate!(:priority => IssuePriority.find_by_name('Normal')) |
|
287 | parent = Issue.generate!(:priority => IssuePriority.find_by_name('Normal')) | |
288 | # Create children |
|
288 | # Create children | |
289 |
child1 = |
|
289 | child1 = parent.generate_child!(:priority => IssuePriority.find_by_name('High')) | |
290 | assert_equal 'High', parent.reload.priority.name |
|
290 | assert_equal 'High', parent.reload.priority.name | |
291 |
child2 = |
|
291 | child2 = child1.generate_child!(:priority => IssuePriority.find_by_name('Immediate')) | |
292 | assert_equal 'Immediate', child1.reload.priority.name |
|
292 | assert_equal 'Immediate', child1.reload.priority.name | |
293 | assert_equal 'Immediate', parent.reload.priority.name |
|
293 | assert_equal 'Immediate', parent.reload.priority.name | |
294 |
child3 = |
|
294 | child3 = parent.generate_child!(:priority => IssuePriority.find_by_name('Low')) | |
295 | assert_equal 'Immediate', parent.reload.priority.name |
|
295 | assert_equal 'Immediate', parent.reload.priority.name | |
296 | # Destroy a child |
|
296 | # Destroy a child | |
297 | child1.destroy |
|
297 | child1.destroy | |
@@ -304,9 +304,9 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
304 |
|
304 | |||
305 | def test_parent_dates_should_be_lowest_start_and_highest_due_dates |
|
305 | def test_parent_dates_should_be_lowest_start_and_highest_due_dates | |
306 | parent = Issue.generate! |
|
306 | parent = Issue.generate! | |
307 |
|
|
307 | parent.generate_child!(:start_date => '2010-01-25', :due_date => '2010-02-15') | |
308 |
|
|
308 | parent.generate_child!( :due_date => '2010-02-13') | |
309 |
|
|
309 | parent.generate_child!(:start_date => '2010-02-01', :due_date => '2010-02-22') | |
310 | parent.reload |
|
310 | parent.reload | |
311 | assert_equal Date.parse('2010-01-25'), parent.start_date |
|
311 | assert_equal Date.parse('2010-01-25'), parent.start_date | |
312 | assert_equal Date.parse('2010-02-22'), parent.due_date |
|
312 | assert_equal Date.parse('2010-02-22'), parent.due_date | |
@@ -314,76 +314,72 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
314 |
|
314 | |||
315 | def test_parent_done_ratio_should_be_average_done_ratio_of_leaves |
|
315 | def test_parent_done_ratio_should_be_average_done_ratio_of_leaves | |
316 | parent = Issue.generate! |
|
316 | parent = Issue.generate! | |
317 | Issue.generate!(:done_ratio => 20, :parent_issue_id => parent.id) |
|
317 | parent.generate_child!(:done_ratio => 20) | |
318 | assert_equal 20, parent.reload.done_ratio |
|
318 | assert_equal 20, parent.reload.done_ratio | |
319 | Issue.generate!(:done_ratio => 70, :parent_issue_id => parent.id) |
|
319 | parent.generate_child!(:done_ratio => 70) | |
320 | assert_equal 45, parent.reload.done_ratio |
|
320 | assert_equal 45, parent.reload.done_ratio | |
321 |
|
321 | |||
322 |
child = |
|
322 | child = parent.generate_child!(:done_ratio => 0) | |
323 | assert_equal 30, parent.reload.done_ratio |
|
323 | assert_equal 30, parent.reload.done_ratio | |
324 |
|
324 | |||
325 | Issue.generate!(:done_ratio => 30, :parent_issue_id => child.id) |
|
325 | child.generate_child!(:done_ratio => 30) | |
326 | assert_equal 30, child.reload.done_ratio |
|
326 | assert_equal 30, child.reload.done_ratio | |
327 | assert_equal 40, parent.reload.done_ratio |
|
327 | assert_equal 40, parent.reload.done_ratio | |
328 | end |
|
328 | end | |
329 |
|
329 | |||
330 | def test_parent_done_ratio_should_be_weighted_by_estimated_times_if_any |
|
330 | def test_parent_done_ratio_should_be_weighted_by_estimated_times_if_any | |
331 | parent = Issue.generate! |
|
331 | parent = Issue.generate! | |
332 |
|
|
332 | parent.generate_child!(:estimated_hours => 10, :done_ratio => 20) | |
333 | assert_equal 20, parent.reload.done_ratio |
|
333 | assert_equal 20, parent.reload.done_ratio | |
334 |
|
|
334 | parent.generate_child!(:estimated_hours => 20, :done_ratio => 50) | |
335 | assert_equal (50 * 20 + 20 * 10) / 30, parent.reload.done_ratio |
|
335 | assert_equal (50 * 20 + 20 * 10) / 30, parent.reload.done_ratio | |
336 | end |
|
336 | end | |
337 |
|
337 | |||
338 | def test_parent_done_ratio_with_child_estimate_to_0_should_reach_100 |
|
338 | def test_parent_done_ratio_with_child_estimate_to_0_should_reach_100 | |
339 | parent = Issue.generate! |
|
339 | parent = Issue.generate! | |
340 | issue1 = Issue.generate!(:parent_issue_id => parent.id) |
|
340 | issue1 = parent.generate_child! | |
341 |
issue2 = |
|
341 | issue2 = parent.generate_child!(:estimated_hours => 0) | |
342 | assert_equal 0, parent.reload.done_ratio |
|
342 | assert_equal 0, parent.reload.done_ratio | |
343 | issue1.reload.update_attribute :status_id, 5 |
|
343 | issue1.reload.close! | |
344 | assert_equal 50, parent.reload.done_ratio |
|
344 | assert_equal 50, parent.reload.done_ratio | |
345 | issue2.reload.update_attribute :status_id, 5 |
|
345 | issue2.reload.close! | |
346 | assert_equal 100, parent.reload.done_ratio |
|
346 | assert_equal 100, parent.reload.done_ratio | |
347 | end |
|
347 | end | |
348 |
|
348 | |||
349 | def test_parent_estimate_should_be_sum_of_leaves |
|
349 | def test_parent_estimate_should_be_sum_of_leaves | |
350 | parent = Issue.generate! |
|
350 | parent = Issue.generate! | |
351 |
|
|
351 | parent.generate_child!(:estimated_hours => nil) | |
352 | assert_equal nil, parent.reload.estimated_hours |
|
352 | assert_equal nil, parent.reload.estimated_hours | |
353 |
|
|
353 | parent.generate_child!(:estimated_hours => 5) | |
354 | assert_equal 5, parent.reload.estimated_hours |
|
354 | assert_equal 5, parent.reload.estimated_hours | |
355 |
|
|
355 | parent.generate_child!(:estimated_hours => 7) | |
356 | assert_equal 12, parent.reload.estimated_hours |
|
356 | assert_equal 12, parent.reload.estimated_hours | |
357 | end |
|
357 | end | |
358 |
|
358 | |||
359 | def test_done_ratio_of_parent_with_a_child_without_estimated_time_should_not_exceed_100 |
|
359 | def test_done_ratio_of_parent_with_a_child_without_estimated_time_should_not_exceed_100 | |
360 | parent = Issue.generate! |
|
360 | parent = Issue.generate! | |
361 |
|
|
361 | parent.generate_child!(:estimated_hours => 40) | |
362 |
|
|
362 | parent.generate_child!(:estimated_hours => 40) | |
363 |
|
|
363 | parent.generate_child!(:estimated_hours => 20) | |
364 | Issue.generate!(:parent_issue_id => parent.id) |
|
364 | parent.generate_child! | |
365 |
parent.reload.children.each |
|
365 | parent.reload.children.each(&:close!) | |
366 | child.update_attribute :status_id, 5 |
|
|||
367 | end |
|
|||
368 | assert_equal 100, parent.reload.done_ratio |
|
366 | assert_equal 100, parent.reload.done_ratio | |
369 | end |
|
367 | end | |
370 |
|
368 | |||
371 | def test_done_ratio_of_parent_with_a_child_with_estimated_time_at_0_should_not_exceed_100 |
|
369 | def test_done_ratio_of_parent_with_a_child_with_estimated_time_at_0_should_not_exceed_100 | |
372 | parent = Issue.generate! |
|
370 | parent = Issue.generate! | |
373 |
|
|
371 | parent.generate_child!(:estimated_hours => 40) | |
374 |
|
|
372 | parent.generate_child!(:estimated_hours => 40) | |
375 |
|
|
373 | parent.generate_child!(:estimated_hours => 20) | |
376 |
|
|
374 | parent.generate_child!(:estimated_hours => 0) | |
377 |
parent.reload.children.each |
|
375 | parent.reload.children.each(&:close!) | |
378 | child.update_attribute :status_id, 5 |
|
|||
379 | end |
|
|||
380 | assert_equal 100, parent.reload.done_ratio |
|
376 | assert_equal 100, parent.reload.done_ratio | |
381 | end |
|
377 | end | |
382 |
|
378 | |||
383 | def test_move_parent_updates_old_parent_attributes |
|
379 | def test_move_parent_updates_old_parent_attributes | |
384 | first_parent = Issue.generate! |
|
380 | first_parent = Issue.generate! | |
385 | second_parent = Issue.generate! |
|
381 | second_parent = Issue.generate! | |
386 |
child = |
|
382 | child = first_parent.generate_child!(:estimated_hours => 5) | |
387 | assert_equal 5, first_parent.reload.estimated_hours |
|
383 | assert_equal 5, first_parent.reload.estimated_hours | |
388 | child.update_attributes(:estimated_hours => 7, :parent_issue_id => second_parent.id) |
|
384 | child.update_attributes(:estimated_hours => 7, :parent_issue_id => second_parent.id) | |
389 | assert_equal 7, second_parent.reload.estimated_hours |
|
385 | assert_equal 7, second_parent.reload.estimated_hours | |
@@ -392,8 +388,8 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
392 |
|
388 | |||
393 | def test_reschuling_a_parent_should_reschedule_subtasks |
|
389 | def test_reschuling_a_parent_should_reschedule_subtasks | |
394 | parent = Issue.generate! |
|
390 | parent = Issue.generate! | |
395 |
c1 = |
|
391 | c1 = parent.generate_child!(:start_date => '2010-05-12', :due_date => '2010-05-18') | |
396 |
c2 = |
|
392 | c2 = parent.generate_child!(:start_date => '2010-06-03', :due_date => '2010-06-10') | |
397 | parent.reload |
|
393 | parent.reload | |
398 | parent.reschedule_on!(Date.parse('2010-06-02')) |
|
394 | parent.reschedule_on!(Date.parse('2010-06-02')) | |
399 | c1.reload |
|
395 | c1.reload | |
@@ -407,9 +403,9 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
407 | def test_project_copy_should_copy_issue_tree |
|
403 | def test_project_copy_should_copy_issue_tree | |
408 | p = Project.create!(:name => 'Tree copy', :identifier => 'tree-copy', :tracker_ids => [1, 2]) |
|
404 | p = Project.create!(:name => 'Tree copy', :identifier => 'tree-copy', :tracker_ids => [1, 2]) | |
409 | i1 = Issue.generate!(:project => p, :subject => 'i1') |
|
405 | i1 = Issue.generate!(:project => p, :subject => 'i1') | |
410 |
i2 = |
|
406 | i2 = i1.generate_child!(:project => p, :subject => 'i2') | |
411 |
i3 = |
|
407 | i3 = i1.generate_child!(:project => p, :subject => 'i3') | |
412 |
i4 = |
|
408 | i4 = i2.generate_child!(:project => p, :subject => 'i4') | |
413 | i5 = Issue.generate!(:project => p, :subject => 'i5') |
|
409 | i5 = Issue.generate!(:project => p, :subject => 'i5') | |
414 | c = Project.new(:name => 'Copy', :identifier => 'copy', :tracker_ids => [1, 2]) |
|
410 | c = Project.new(:name => 'Copy', :identifier => 'copy', :tracker_ids => [1, 2]) | |
415 | c.copy(p, :only => 'issues') |
|
411 | c.copy(p, :only => 'issues') |
General Comments 0
You need to be logged in to leave comments.
Login now