Merged r7814 from trunk (#9577).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/1.2-stable@8117 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2011-12-07 21:54:05 +00:00
parent d19a0b70e0
commit 00d1b230e0
2 changed files with 18 additions and 3 deletions

View File

@ -222,6 +222,20 @@ class IssueNestedSetTest < ActiveSupport::TestCase
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]
end
def test_destroy_child_should_update_parent
issue = create_issue!
child1 = create_issue!(:parent_issue_id => issue.id)
child2 = create_issue!(:parent_issue_id => issue.id)
issue.reload
assert_equal [issue.id, 1, 6], [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]
end
def test_destroy_parent_issue_updated_during_children_destroy
parent = create_issue!

View File

@ -162,9 +162,10 @@ module CollectiveIdea #:nodoc:
end
# Rebuilds the left & rights if unset or invalid. Also very useful for converting from acts_as_tree.
def rebuild!
def rebuild!(force=false)
# Don't rebuild a valid tree.
return true if valid?
# valid? doesn't strictly validate the tree
return true if !force && valid?
scope = lambda{|node|}
if acts_as_nested_set_options[:scope]
@ -444,7 +445,7 @@ module CollectiveIdea #:nodoc:
# Prunes a branch off of the tree, shifting all of the elements on the right
# back to the left so the counts still work.
def prune_from_tree
return if right.nil? || left.nil? || leaf? || !self.class.exists?(id)
return if right.nil? || left.nil? || !self.class.exists?(id)
self.class.base_class.transaction do
reload_nested_set