@@ -1316,8 +1316,7 class Issue < ActiveRecord::Base | |||||
1316 | self.root_id = (@parent_issue.nil? ? id : @parent_issue.root_id) |
|
1316 | self.root_id = (@parent_issue.nil? ? id : @parent_issue.root_id) | |
1317 | cond = ["root_id = ? AND lft >= ? AND rgt <= ? ", old_root_id, lft, rgt] |
|
1317 | cond = ["root_id = ? AND lft >= ? AND rgt <= ? ", old_root_id, lft, rgt] | |
1318 | self.class.base_class.select('id').lock(true).where(cond) |
|
1318 | self.class.base_class.select('id').lock(true).where(cond) | |
1319 | target_maxright = nested_set_scope.maximum(right_column_name) || 0 |
|
1319 | offset = right_most_bound + 1 - lft | |
1320 | offset = target_maxright + 1 - lft |
|
|||
1321 | Issue.where(cond). |
|
1320 | Issue.where(cond). | |
1322 | update_all(["root_id = ?, lft = lft + ?, rgt = rgt + ?", root_id, offset, offset]) |
|
1321 | update_all(["root_id = ?, lft = lft + ?, rgt = rgt + ?", root_id, offset, offset]) | |
1323 | self[left_column_name] = lft + offset |
|
1322 | self[left_column_name] = lft + offset |
@@ -86,6 +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 | lft3 = new_issue_lft | |||
89 | child = parent1.generate_child! |
|
90 | child = parent1.generate_child! | |
90 | child.parent_issue_id = nil |
|
91 | child.parent_issue_id = nil | |
91 | child.save! |
|
92 | child.save! | |
@@ -94,7 +95,7 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
94 | parent2.reload |
|
95 | parent2.reload | |
95 | assert_equal [parent1.id, lft1, lft1 + 1], [parent1.root_id, parent1.lft, parent1.rgt] |
|
96 | assert_equal [parent1.id, lft1, lft1 + 1], [parent1.root_id, parent1.lft, parent1.rgt] | |
96 | assert_equal [parent2.id, lft2, lft2 + 1], [parent2.root_id, parent2.lft, parent2.rgt] |
|
97 | assert_equal [parent2.id, lft2, lft2 + 1], [parent2.root_id, parent2.lft, parent2.rgt] | |
97 |
assert_equal [child.id, 1 |
|
98 | assert_equal [child.id, lft3, lft3 + 1], [child.root_id, child.lft, child.rgt] | |
98 | end |
|
99 | end | |
99 |
|
100 | |||
100 | def test_move_a_child_to_another_issue |
|
101 | def test_move_a_child_to_another_issue | |
@@ -145,6 +146,7 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
145 | parent1 = Issue.generate! |
|
146 | parent1 = Issue.generate! | |
146 | child = parent1.generate_child! |
|
147 | child = parent1.generate_child! | |
147 | grandchild = child.generate_child! |
|
148 | grandchild = child.generate_child! | |
|
149 | lft4 = new_issue_lft | |||
148 | child.reload |
|
150 | child.reload | |
149 | child.project = Project.find(2) |
|
151 | child.project = Project.find(2) | |
150 | assert child.save |
|
152 | assert child.save | |
@@ -152,8 +154,10 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
152 | grandchild.reload |
|
154 | grandchild.reload | |
153 | parent1.reload |
|
155 | parent1.reload | |
154 | assert_equal [1, parent1.id, lft1, lft1 + 1], [parent1.project_id, parent1.root_id, parent1.lft, parent1.rgt] |
|
156 | assert_equal [1, parent1.id, lft1, lft1 + 1], [parent1.project_id, parent1.root_id, parent1.lft, parent1.rgt] | |
155 | assert_equal [2, child.id, 1, 4], [child.project_id, child.root_id, child.lft, child.rgt] |
|
157 | assert_equal [2, child.id, lft4, lft4 + 3], | |
156 |
|
|
158 | [child.project_id, child.root_id, child.lft, child.rgt] | |
|
159 | assert_equal [2, child.id, lft4 + 1, lft4 + 2], | |||
|
160 | [grandchild.project_id, grandchild.root_id, grandchild.lft, grandchild.rgt] | |||
157 | end |
|
161 | end | |
158 |
|
162 | |||
159 | def test_moving_an_issue_to_a_descendant_should_not_validate |
|
163 | def test_moving_an_issue_to_a_descendant_should_not_validate |
General Comments 0
You need to be logged in to leave comments.
Login now