end
def test_create_root_issue
+ lft1 = new_issue_lft
issue1 = Issue.generate!
+ lft2 = new_issue_lft
issue2 = Issue.generate!
issue1.reload
issue2.reload
-
- assert_equal [issue1.id, nil, 1, 2], [issue1.root_id, issue1.parent_id, issue1.lft, issue1.rgt]
- assert_equal [issue2.id, nil, 1, 2], [issue2.root_id, issue2.parent_id, issue2.lft, issue2.rgt]
+ assert_equal [issue1.id, nil, lft1, lft1 + 1], [issue1.root_id, issue1.parent_id, issue1.lft, issue1.rgt]
+ assert_equal [issue2.id, nil, lft2, lft2 + 1], [issue2.root_id, issue2.parent_id, issue2.lft, issue2.rgt]
end
def test_create_child_issue
+ lft = new_issue_lft
parent = Issue.generate!
child = Issue.generate!(:parent_issue_id => parent.id)
parent.reload
child.reload
-
- assert_equal [parent.id, nil, 1, 4], [parent.root_id, parent.parent_id, parent.lft, parent.rgt]
- assert_equal [parent.id, parent.id, 2, 3], [child.root_id, child.parent_id, child.lft, child.rgt]
+ assert_equal [parent.id, nil, lft, lft + 3], [parent.root_id, parent.parent_id, parent.lft, parent.rgt]
+ assert_equal [parent.id, parent.id, lft + 1, lft + 2], [child.root_id, child.parent_id, child.lft, child.rgt]
end
def test_creating_a_child_in_a_subproject_should_validate
end
def test_move_a_root_to_child
+ lft = new_issue_lft
parent1 = Issue.generate!
parent2 = Issue.generate!
child = Issue.generate!(:parent_issue_id => parent1.id)
-
parent2.parent_issue_id = parent1.id
parent2.save!
child.reload
parent1.reload
parent2.reload
-
- assert_equal [parent1.id, 1, 6], [parent1.root_id, parent1.lft, parent1.rgt]
- assert_equal [parent1.id, 4, 5], [parent2.root_id, parent2.lft, parent2.rgt]
- assert_equal [parent1.id, 2, 3], [child.root_id, child.lft, child.rgt]
+ assert_equal [parent1.id, lft, lft + 5], [parent1.root_id, parent1.lft, parent1.rgt]
+ assert_equal [parent1.id, lft + 3, lft + 4], [parent2.root_id, parent2.lft, parent2.rgt]
+ assert_equal [parent1.id, lft + 1, lft + 2], [child.root_id, child.lft, child.rgt]
end
def test_move_a_child_to_root
+ lft1 = new_issue_lft
parent1 = Issue.generate!
+ lft2 = new_issue_lft
parent2 = Issue.generate!
child = Issue.generate!(:parent_issue_id => parent1.id)
-
child.parent_issue_id = nil
child.save!
child.reload
parent1.reload
parent2.reload
-
- assert_equal [parent1.id, 1, 2], [parent1.root_id, parent1.lft, parent1.rgt]
- assert_equal [parent2.id, 1, 2], [parent2.root_id, parent2.lft, parent2.rgt]
+ assert_equal [parent1.id, lft1, lft1 + 1], [parent1.root_id, parent1.lft, parent1.rgt]
+ assert_equal [parent2.id, lft2, lft2 + 1], [parent2.root_id, parent2.lft, parent2.rgt]
assert_equal [child.id, 1, 2], [child.root_id, child.lft, child.rgt]
end
def test_move_a_child_to_another_issue
+ lft1 = new_issue_lft
parent1 = Issue.generate!
+ lft2 = new_issue_lft
parent2 = Issue.generate!
child = Issue.generate!(:parent_issue_id => parent1.id)
-
child.parent_issue_id = parent2.id
child.save!
child.reload
parent1.reload
parent2.reload
-
- assert_equal [parent1.id, 1, 2], [parent1.root_id, parent1.lft, parent1.rgt]
- assert_equal [parent2.id, 1, 4], [parent2.root_id, parent2.lft, parent2.rgt]
- assert_equal [parent2.id, 2, 3], [child.root_id, child.lft, child.rgt]
+ assert_equal [parent1.id, lft1, lft1 + 1], [parent1.root_id, parent1.lft, parent1.rgt]
+ assert_equal [parent2.id, lft2, lft2 + 3], [parent2.root_id, parent2.lft, parent2.rgt]
+ assert_equal [parent2.id, lft2 + 1, lft2 + 2], [child.root_id, child.lft, child.rgt]
end
def test_move_a_child_with_descendants_to_another_issue
+ lft1 = new_issue_lft
parent1 = Issue.generate!
+ lft2 = new_issue_lft
parent2 = Issue.generate!
child = Issue.generate!(:parent_issue_id => parent1.id)
grandchild = Issue.generate!(:parent_issue_id => child.id)
-
parent1.reload
parent2.reload
child.reload
grandchild.reload
-
- assert_equal [parent1.id, 1, 6], [parent1.root_id, parent1.lft, parent1.rgt]
- assert_equal [parent2.id, 1, 2], [parent2.root_id, parent2.lft, parent2.rgt]
- assert_equal [parent1.id, 2, 5], [child.root_id, child.lft, child.rgt]
- assert_equal [parent1.id, 3, 4], [grandchild.root_id, grandchild.lft, grandchild.rgt]
-
+ assert_equal [parent1.id, lft1, lft1 + 5], [parent1.root_id, parent1.lft, parent1.rgt]
+ assert_equal [parent2.id, lft2, lft2 + 1], [parent2.root_id, parent2.lft, parent2.rgt]
+ assert_equal [parent1.id, lft1 + 1, lft1 + 4], [child.root_id, child.lft, child.rgt]
+ assert_equal [parent1.id, lft1 + 2, lft1 + 3], [grandchild.root_id, grandchild.lft, grandchild.rgt]
child.reload.parent_issue_id = parent2.id
child.save!
child.reload
grandchild.reload
parent1.reload
parent2.reload
-
- assert_equal [parent1.id, 1, 2], [parent1.root_id, parent1.lft, parent1.rgt]
- assert_equal [parent2.id, 1, 6], [parent2.root_id, parent2.lft, parent2.rgt]
- assert_equal [parent2.id, 2, 5], [child.root_id, child.lft, child.rgt]
- assert_equal [parent2.id, 3, 4], [grandchild.root_id, grandchild.lft, grandchild.rgt]
+ assert_equal [parent1.id, lft1, lft1 + 1], [parent1.root_id, parent1.lft, parent1.rgt]
+ assert_equal [parent2.id, lft2, lft2 + 5], [parent2.root_id, parent2.lft, parent2.rgt]
+ assert_equal [parent2.id, lft2 + 1, lft2 + 4], [child.root_id, child.lft, child.rgt]
+ assert_equal [parent2.id, lft2 + 2, lft2 + 3], [grandchild.root_id, grandchild.lft, grandchild.rgt]
end
def test_move_a_child_with_descendants_to_another_project
+ lft1 = new_issue_lft
parent1 = Issue.generate!
child = Issue.generate!(:parent_issue_id => parent1.id)
grandchild = Issue.generate!(:parent_issue_id => child.id)
-
child.reload
child.project = Project.find(2)
assert child.save
child.reload
grandchild.reload
parent1.reload
-
- assert_equal [1, parent1.id, 1, 2], [parent1.project_id, parent1.root_id, parent1.lft, parent1.rgt]
+ assert_equal [1, parent1.id, lft1, lft1 + 1], [parent1.project_id, parent1.root_id, parent1.lft, parent1.rgt]
assert_equal [2, child.id, 1, 4], [child.project_id, child.root_id, child.lft, child.rgt]
assert_equal [2, child.id, 2, 3], [grandchild.project_id, grandchild.root_id, grandchild.lft, grandchild.rgt]
end
end
def test_destroy_should_destroy_children
+ lft1 = new_issue_lft
issue1 = Issue.generate!
issue2 = Issue.generate!
issue3 = Issue.generate!(:parent_issue_id => issue2.id)
issue4 = Issue.generate!(:parent_issue_id => issue1.id)
-
issue3.init_journal(User.find(2))
issue3.subject = 'child with journal'
issue3.save!
-
assert_difference 'Issue.count', -2 do
assert_difference 'Journal.count', -1 do
assert_difference 'JournalDetail.count', -1 do
end
end
end
-
issue1.reload
issue4.reload
assert !Issue.exists?(issue2.id)
assert !Issue.exists?(issue3.id)
- assert_equal [issue1.id, 1, 4], [issue1.root_id, issue1.lft, issue1.rgt]
- assert_equal [issue1.id, 2, 3], [issue4.root_id, issue4.lft, issue4.rgt]
+ assert_equal [issue1.id, lft1, lft1 + 3], [issue1.root_id, issue1.lft, issue1.rgt]
+ assert_equal [issue1.id, lft1 + 1, lft1 + 2], [issue4.root_id, issue4.lft, issue4.rgt]
end
-
+
def test_destroy_child_should_update_parent
+ lft1 = new_issue_lft
issue = Issue.generate!
child1 = Issue.generate!(:parent_issue_id => issue.id)
child2 = Issue.generate!(:parent_issue_id => issue.id)
-
issue.reload
- assert_equal [issue.id, 1, 6], [issue.root_id, issue.lft, issue.rgt]
-
+ assert_equal [issue.id, lft1, lft1 + 5], [issue.root_id, issue.lft, issue.rgt]
child2.reload.destroy
-
issue.reload
- assert_equal [issue.id, 1, 4], [issue.root_id, issue.lft, issue.rgt]
+ assert_equal [issue.id, lft1, lft1 + 3], [issue.root_id, issue.lft, issue.rgt]
end
def test_destroy_parent_issue_updated_during_children_destroy
end
def test_destroy_issue_with_grand_child
+ lft1 = new_issue_lft
parent = Issue.generate!
issue = Issue.generate!(:parent_issue_id => parent.id)
child = Issue.generate!(:parent_issue_id => issue.id)
grandchild1 = Issue.generate!(:parent_issue_id => child.id)
grandchild2 = Issue.generate!(:parent_issue_id => child.id)
-
assert_difference 'Issue.count', -4 do
Issue.find(issue.id).destroy
parent.reload
- assert_equal [1, 2], [parent.lft, parent.rgt]
+ assert_equal [lft1, lft1 + 1], [parent.lft, parent.rgt]
end
end