@@ -28,8 +28,8 class IssueNestedSetTest < ActiveSupport::TestCase | |||
|
28 | 28 | :time_entries |
|
29 | 29 | |
|
30 | 30 | def test_create_root_issue |
|
31 |
issue1 = |
|
|
32 |
issue2 = |
|
|
31 | issue1 = Issue.generate! | |
|
32 | issue2 = Issue.generate! | |
|
33 | 33 | issue1.reload |
|
34 | 34 | issue2.reload |
|
35 | 35 | |
@@ -38,8 +38,8 class IssueNestedSetTest < ActiveSupport::TestCase | |||
|
38 | 38 | end |
|
39 | 39 | |
|
40 | 40 | def test_create_child_issue |
|
41 |
parent = |
|
|
42 |
child = |
|
|
41 | parent = Issue.generate! | |
|
42 | child = Issue.generate!(:parent_issue_id => parent.id) | |
|
43 | 43 | parent.reload |
|
44 | 44 | child.reload |
|
45 | 45 | |
@@ -48,7 +48,7 class IssueNestedSetTest < ActiveSupport::TestCase | |||
|
48 | 48 | end |
|
49 | 49 | |
|
50 | 50 | def test_creating_a_child_in_a_subproject_should_validate |
|
51 |
issue = |
|
|
51 | issue = Issue.generate! | |
|
52 | 52 | child = Issue.new(:project_id => 3, :tracker_id => 2, :author_id => 1, |
|
53 | 53 | :subject => 'child', :parent_issue_id => issue.id) |
|
54 | 54 | assert_save child |
@@ -56,7 +56,7 class IssueNestedSetTest < ActiveSupport::TestCase | |||
|
56 | 56 | end |
|
57 | 57 | |
|
58 | 58 | def test_creating_a_child_in_an_invalid_project_should_not_validate |
|
59 |
issue = |
|
|
59 | issue = Issue.generate! | |
|
60 | 60 | child = Issue.new(:project_id => 2, :tracker_id => 1, :author_id => 1, |
|
61 | 61 | :subject => 'child', :parent_issue_id => issue.id) |
|
62 | 62 | assert !child.save |
@@ -64,9 +64,9 class IssueNestedSetTest < ActiveSupport::TestCase | |||
|
64 | 64 | end |
|
65 | 65 | |
|
66 | 66 | def test_move_a_root_to_child |
|
67 |
parent1 = |
|
|
68 |
parent2 = |
|
|
69 |
child = |
|
|
67 | parent1 = Issue.generate! | |
|
68 | parent2 = Issue.generate! | |
|
69 | child = Issue.generate!(:parent_issue_id => parent1.id) | |
|
70 | 70 | |
|
71 | 71 | parent2.parent_issue_id = parent1.id |
|
72 | 72 | parent2.save! |
@@ -80,9 +80,9 class IssueNestedSetTest < ActiveSupport::TestCase | |||
|
80 | 80 | end |
|
81 | 81 | |
|
82 | 82 | def test_move_a_child_to_root |
|
83 |
parent1 = |
|
|
84 |
parent2 = |
|
|
85 |
child = |
|
|
83 | parent1 = Issue.generate! | |
|
84 | parent2 = Issue.generate! | |
|
85 | child = Issue.generate!(:parent_issue_id => parent1.id) | |
|
86 | 86 | |
|
87 | 87 | child.parent_issue_id = nil |
|
88 | 88 | child.save! |
@@ -96,9 +96,9 class IssueNestedSetTest < ActiveSupport::TestCase | |||
|
96 | 96 | end |
|
97 | 97 | |
|
98 | 98 | def test_move_a_child_to_another_issue |
|
99 |
parent1 = |
|
|
100 |
parent2 = |
|
|
101 |
child = |
|
|
99 | parent1 = Issue.generate! | |
|
100 | parent2 = Issue.generate! | |
|
101 | child = Issue.generate!(:parent_issue_id => parent1.id) | |
|
102 | 102 | |
|
103 | 103 | child.parent_issue_id = parent2.id |
|
104 | 104 | child.save! |
@@ -112,10 +112,10 class IssueNestedSetTest < ActiveSupport::TestCase | |||
|
112 | 112 | end |
|
113 | 113 | |
|
114 | 114 | def test_move_a_child_with_descendants_to_another_issue |
|
115 |
parent1 = |
|
|
116 |
parent2 = |
|
|
117 |
child = |
|
|
118 |
grandchild = |
|
|
115 | parent1 = Issue.generate! | |
|
116 | parent2 = Issue.generate! | |
|
117 | child = Issue.generate!(:parent_issue_id => parent1.id) | |
|
118 | grandchild = Issue.generate!(:parent_issue_id => child.id) | |
|
119 | 119 | |
|
120 | 120 | parent1.reload |
|
121 | 121 | parent2.reload |
@@ -141,9 +141,9 class IssueNestedSetTest < ActiveSupport::TestCase | |||
|
141 | 141 | end |
|
142 | 142 | |
|
143 | 143 | def test_move_a_child_with_descendants_to_another_project |
|
144 |
parent1 = |
|
|
145 |
child = |
|
|
146 |
grandchild = |
|
|
144 | parent1 = Issue.generate! | |
|
145 | child = Issue.generate!(:parent_issue_id => parent1.id) | |
|
146 | grandchild = Issue.generate!(:parent_issue_id => child.id) | |
|
147 | 147 | |
|
148 | 148 | child.reload |
|
149 | 149 | child.project = Project.find(2) |
@@ -158,10 +158,10 class IssueNestedSetTest < ActiveSupport::TestCase | |||
|
158 | 158 | end |
|
159 | 159 | |
|
160 | 160 | def test_moving_an_issue_to_a_descendant_should_not_validate |
|
161 |
parent1 = |
|
|
162 |
parent2 = |
|
|
163 |
child = |
|
|
164 |
grandchild = |
|
|
161 | parent1 = Issue.generate! | |
|
162 | parent2 = Issue.generate! | |
|
163 | child = Issue.generate!(:parent_issue_id => parent1.id) | |
|
164 | grandchild = Issue.generate!(:parent_issue_id => child.id) | |
|
165 | 165 | |
|
166 | 166 | child.reload |
|
167 | 167 | child.parent_issue_id = grandchild.id |
@@ -170,10 +170,10 class IssueNestedSetTest < ActiveSupport::TestCase | |||
|
170 | 170 | end |
|
171 | 171 | |
|
172 | 172 | def test_moving_an_issue_should_keep_valid_relations_only |
|
173 |
issue1 = |
|
|
174 |
issue2 = |
|
|
175 |
issue3 = |
|
|
176 |
issue4 = |
|
|
173 | issue1 = Issue.generate! | |
|
174 | issue2 = Issue.generate! | |
|
175 | issue3 = Issue.generate!(:parent_issue_id => issue2.id) | |
|
176 | issue4 = Issue.generate! | |
|
177 | 177 | r1 = IssueRelation.create!(:issue_from => issue1, :issue_to => issue2, :relation_type => IssueRelation::TYPE_PRECEDES) |
|
178 | 178 | r2 = IssueRelation.create!(:issue_from => issue1, :issue_to => issue3, :relation_type => IssueRelation::TYPE_PRECEDES) |
|
179 | 179 | r3 = IssueRelation.create!(:issue_from => issue2, :issue_to => issue4, :relation_type => IssueRelation::TYPE_PRECEDES) |
@@ -186,10 +186,10 class IssueNestedSetTest < ActiveSupport::TestCase | |||
|
186 | 186 | end |
|
187 | 187 | |
|
188 | 188 | def test_destroy_should_destroy_children |
|
189 |
issue1 = |
|
|
190 |
issue2 = |
|
|
191 |
issue3 = |
|
|
192 |
issue4 = |
|
|
189 | issue1 = Issue.generate! | |
|
190 | issue2 = Issue.generate! | |
|
191 | issue3 = Issue.generate!(:parent_issue_id => issue2.id) | |
|
192 | issue4 = Issue.generate!(:parent_issue_id => issue1.id) | |
|
193 | 193 | |
|
194 | 194 | issue3.init_journal(User.find(2)) |
|
195 | 195 | issue3.subject = 'child with journal' |
@@ -212,9 +212,9 class IssueNestedSetTest < ActiveSupport::TestCase | |||
|
212 | 212 | end |
|
213 | 213 | |
|
214 | 214 | def test_destroy_child_should_update_parent |
|
215 |
issue = |
|
|
216 |
child1 = |
|
|
217 |
child2 = |
|
|
215 | issue = Issue.generate! | |
|
216 | child1 = Issue.generate!(:parent_issue_id => issue.id) | |
|
217 | child2 = Issue.generate!(:parent_issue_id => issue.id) | |
|
218 | 218 | |
|
219 | 219 | issue.reload |
|
220 | 220 | assert_equal [issue.id, 1, 6], [issue.root_id, issue.lft, issue.rgt] |
@@ -226,9 +226,9 class IssueNestedSetTest < ActiveSupport::TestCase | |||
|
226 | 226 | end |
|
227 | 227 | |
|
228 | 228 | def test_destroy_parent_issue_updated_during_children_destroy |
|
229 |
parent = |
|
|
230 |
|
|
|
231 |
|
|
|
229 | parent = Issue.generate! | |
|
230 | Issue.generate!(:start_date => Date.today, :parent_issue_id => parent.id) | |
|
231 | Issue.generate!(:start_date => 2.days.from_now, :parent_issue_id => parent.id) | |
|
232 | 232 | |
|
233 | 233 | assert_difference 'Issue.count', -3 do |
|
234 | 234 | Issue.find(parent.id).destroy |
@@ -256,11 +256,11 class IssueNestedSetTest < ActiveSupport::TestCase | |||
|
256 | 256 | end |
|
257 | 257 | |
|
258 | 258 | def test_destroy_issue_with_grand_child |
|
259 |
parent = |
|
|
260 |
issue = |
|
|
261 |
child = |
|
|
262 |
grandchild1 = |
|
|
263 |
grandchild2 = |
|
|
259 | parent = Issue.generate! | |
|
260 | issue = Issue.generate!(:parent_issue_id => parent.id) | |
|
261 | child = Issue.generate!(:parent_issue_id => issue.id) | |
|
262 | grandchild1 = Issue.generate!(:parent_issue_id => child.id) | |
|
263 | grandchild2 = Issue.generate!(:parent_issue_id => child.id) | |
|
264 | 264 | |
|
265 | 265 | assert_difference 'Issue.count', -4 do |
|
266 | 266 | Issue.find(issue.id).destroy |
@@ -270,14 +270,14 class IssueNestedSetTest < ActiveSupport::TestCase | |||
|
270 | 270 | end |
|
271 | 271 | |
|
272 | 272 | def test_parent_priority_should_be_the_highest_child_priority |
|
273 |
parent = |
|
|
273 | parent = Issue.generate!(:priority => IssuePriority.find_by_name('Normal')) | |
|
274 | 274 | # Create children |
|
275 |
child1 = |
|
|
275 | child1 = Issue.generate!(:priority => IssuePriority.find_by_name('High'), :parent_issue_id => parent.id) | |
|
276 | 276 | assert_equal 'High', parent.reload.priority.name |
|
277 |
child2 = |
|
|
277 | child2 = Issue.generate!(:priority => IssuePriority.find_by_name('Immediate'), :parent_issue_id => child1.id) | |
|
278 | 278 | assert_equal 'Immediate', child1.reload.priority.name |
|
279 | 279 | assert_equal 'Immediate', parent.reload.priority.name |
|
280 |
child3 = |
|
|
280 | child3 = Issue.generate!(:priority => IssuePriority.find_by_name('Low'), :parent_issue_id => parent.id) | |
|
281 | 281 | assert_equal 'Immediate', parent.reload.priority.name |
|
282 | 282 | # Destroy a child |
|
283 | 283 | child1.destroy |
@@ -289,52 +289,52 class IssueNestedSetTest < ActiveSupport::TestCase | |||
|
289 | 289 | end |
|
290 | 290 | |
|
291 | 291 | def test_parent_dates_should_be_lowest_start_and_highest_due_dates |
|
292 |
parent = |
|
|
293 |
|
|
|
294 |
|
|
|
295 |
|
|
|
292 | parent = Issue.generate! | |
|
293 | Issue.generate!(:start_date => '2010-01-25', :due_date => '2010-02-15', :parent_issue_id => parent.id) | |
|
294 | Issue.generate!( :due_date => '2010-02-13', :parent_issue_id => parent.id) | |
|
295 | Issue.generate!(:start_date => '2010-02-01', :due_date => '2010-02-22', :parent_issue_id => parent.id) | |
|
296 | 296 | parent.reload |
|
297 | 297 | assert_equal Date.parse('2010-01-25'), parent.start_date |
|
298 | 298 | assert_equal Date.parse('2010-02-22'), parent.due_date |
|
299 | 299 | end |
|
300 | 300 | |
|
301 | 301 | def test_parent_done_ratio_should_be_average_done_ratio_of_leaves |
|
302 |
parent = |
|
|
303 |
|
|
|
302 | parent = Issue.generate! | |
|
303 | Issue.generate!(:done_ratio => 20, :parent_issue_id => parent.id) | |
|
304 | 304 | assert_equal 20, parent.reload.done_ratio |
|
305 |
|
|
|
305 | Issue.generate!(:done_ratio => 70, :parent_issue_id => parent.id) | |
|
306 | 306 | assert_equal 45, parent.reload.done_ratio |
|
307 | 307 | |
|
308 |
child = |
|
|
308 | child = Issue.generate!(:done_ratio => 0, :parent_issue_id => parent.id) | |
|
309 | 309 | assert_equal 30, parent.reload.done_ratio |
|
310 | 310 | |
|
311 |
|
|
|
311 | Issue.generate!(:done_ratio => 30, :parent_issue_id => child.id) | |
|
312 | 312 | assert_equal 30, child.reload.done_ratio |
|
313 | 313 | assert_equal 40, parent.reload.done_ratio |
|
314 | 314 | end |
|
315 | 315 | |
|
316 | 316 | def test_parent_done_ratio_should_be_weighted_by_estimated_times_if_any |
|
317 |
parent = |
|
|
318 |
|
|
|
317 | parent = Issue.generate! | |
|
318 | Issue.generate!(:estimated_hours => 10, :done_ratio => 20, :parent_issue_id => parent.id) | |
|
319 | 319 | assert_equal 20, parent.reload.done_ratio |
|
320 |
|
|
|
320 | Issue.generate!(:estimated_hours => 20, :done_ratio => 50, :parent_issue_id => parent.id) | |
|
321 | 321 | assert_equal (50 * 20 + 20 * 10) / 30, parent.reload.done_ratio |
|
322 | 322 | end |
|
323 | 323 | |
|
324 | 324 | def test_parent_estimate_should_be_sum_of_leaves |
|
325 |
parent = |
|
|
326 |
|
|
|
325 | parent = Issue.generate! | |
|
326 | Issue.generate!(:estimated_hours => nil, :parent_issue_id => parent.id) | |
|
327 | 327 | assert_equal nil, parent.reload.estimated_hours |
|
328 |
|
|
|
328 | Issue.generate!(:estimated_hours => 5, :parent_issue_id => parent.id) | |
|
329 | 329 | assert_equal 5, parent.reload.estimated_hours |
|
330 |
|
|
|
330 | Issue.generate!(:estimated_hours => 7, :parent_issue_id => parent.id) | |
|
331 | 331 | assert_equal 12, parent.reload.estimated_hours |
|
332 | 332 | end |
|
333 | 333 | |
|
334 | 334 | def test_move_parent_updates_old_parent_attributes |
|
335 |
first_parent = |
|
|
336 |
second_parent = |
|
|
337 |
child = |
|
|
335 | first_parent = Issue.generate! | |
|
336 | second_parent = Issue.generate! | |
|
337 | child = Issue.generate!(:estimated_hours => 5, :parent_issue_id => first_parent.id) | |
|
338 | 338 | assert_equal 5, first_parent.reload.estimated_hours |
|
339 | 339 | child.update_attributes(:estimated_hours => 7, :parent_issue_id => second_parent.id) |
|
340 | 340 | assert_equal 7, second_parent.reload.estimated_hours |
@@ -342,9 +342,9 class IssueNestedSetTest < ActiveSupport::TestCase | |||
|
342 | 342 | end |
|
343 | 343 | |
|
344 | 344 | def test_reschuling_a_parent_should_reschedule_subtasks |
|
345 |
parent = |
|
|
346 |
c1 = |
|
|
347 |
c2 = |
|
|
345 | parent = Issue.generate! | |
|
346 | c1 = Issue.generate!(:start_date => '2010-05-12', :due_date => '2010-05-18', :parent_issue_id => parent.id) | |
|
347 | c2 = Issue.generate!(:start_date => '2010-06-03', :due_date => '2010-06-10', :parent_issue_id => parent.id) | |
|
348 | 348 | parent.reload |
|
349 | 349 | parent.reschedule_after(Date.parse('2010-06-02')) |
|
350 | 350 | c1.reload |
@@ -357,11 +357,11 class IssueNestedSetTest < ActiveSupport::TestCase | |||
|
357 | 357 | |
|
358 | 358 | def test_project_copy_should_copy_issue_tree |
|
359 | 359 | p = Project.create!(:name => 'Tree copy', :identifier => 'tree-copy', :tracker_ids => [1, 2]) |
|
360 |
i1 = |
|
|
361 |
i2 = |
|
|
362 |
i3 = |
|
|
363 |
i4 = |
|
|
364 |
i5 = |
|
|
360 | i1 = Issue.generate!(:project => p, :subject => 'i1') | |
|
361 | i2 = Issue.generate!(:project => p, :subject => 'i2', :parent_issue_id => i1.id) | |
|
362 | i3 = Issue.generate!(:project => p, :subject => 'i3', :parent_issue_id => i1.id) | |
|
363 | i4 = Issue.generate!(:project => p, :subject => 'i4', :parent_issue_id => i2.id) | |
|
364 | i5 = Issue.generate!(:project => p, :subject => 'i5') | |
|
365 | 365 | c = Project.new(:name => 'Copy', :identifier => 'copy', :tracker_ids => [1, 2]) |
|
366 | 366 | c.copy(p, :only => 'issues') |
|
367 | 367 | c.reload |
@@ -374,9 +374,4 class IssueNestedSetTest < ActiveSupport::TestCase | |||
|
374 | 374 | assert_equal ic2, ic4.parent |
|
375 | 375 | assert ic5.root? |
|
376 | 376 | end |
|
377 | ||
|
378 | # Helper that creates an issue with default attributes | |
|
379 | def create_issue!(attributes={}) | |
|
380 | Issue.create!({:project_id => 1, :tracker_id => 1, :author_id => 1, :subject => 'test'}.merge(attributes)) | |
|
381 | end | |
|
382 | 377 | end |
@@ -30,9 +30,9 class IssueTransactionTest < ActiveSupport::TestCase | |||
|
30 | 30 | self.use_transactional_fixtures = false |
|
31 | 31 | |
|
32 | 32 | def test_invalid_move_to_another_project |
|
33 |
parent1 = |
|
|
34 |
child = |
|
|
35 |
grandchild = |
|
|
33 | parent1 = Issue.generate! | |
|
34 | child = Issue.generate!(:parent_issue_id => parent1.id) | |
|
35 | grandchild = Issue.generate!(:parent_issue_id => child.id, :tracker_id => 2) | |
|
36 | 36 | Project.find(2).tracker_ids = [1] |
|
37 | 37 | |
|
38 | 38 | parent1.reload |
@@ -51,9 +51,4 class IssueTransactionTest < ActiveSupport::TestCase | |||
|
51 | 51 | assert_equal [1, parent1.id, 2, 5], [child.project_id, child.root_id, child.lft, child.rgt] |
|
52 | 52 | assert_equal [1, parent1.id, 3, 4], [grandchild.project_id, grandchild.root_id, grandchild.lft, grandchild.rgt] |
|
53 | 53 | end |
|
54 | ||
|
55 | # Helper that creates an issue with default attributes | |
|
56 | def create_issue!(attributes={}) | |
|
57 | Issue.create!({:project_id => 1, :tracker_id => 1, :author_id => 1, :subject => 'test'}.merge(attributes)) | |
|
58 | end | |
|
59 | 54 | end |
General Comments 0
You need to be logged in to leave comments.
Login now