Merged r6311 from trunk (#8880).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/1.2-stable@7769 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2011-11-11 11:40:56 +00:00
parent f22ff1f1c2
commit 21910aa428
2 changed files with 22 additions and 8 deletions

View File

@ -252,6 +252,20 @@ class IssueNestedSetTest < ActiveSupport::TestCase
root = Issue.find(root.id) root = Issue.find(root.id)
assert root.leaf?, "Root issue is not a leaf (lft: #{root.lft}, rgt: #{root.rgt})" assert root.leaf?, "Root issue is not a leaf (lft: #{root.lft}, rgt: #{root.rgt})"
end end
def test_destroy_issue_with_grand_child
parent = create_issue!
issue = create_issue!(:parent_issue_id => parent.id)
child = create_issue!(:parent_issue_id => issue.id)
grandchild1 = create_issue!(:parent_issue_id => child.id)
grandchild2 = create_issue!(: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]
end
end
def test_parent_priority_should_be_the_highest_child_priority def test_parent_priority_should_be_the_highest_child_priority
parent = create_issue!(:priority => IssuePriority.find_by_name('Normal')) parent = create_issue!(:priority => IssuePriority.find_by_name('Normal'))

View File

@ -446,16 +446,16 @@ module CollectiveIdea #:nodoc:
def prune_from_tree def prune_from_tree
return if right.nil? || left.nil? || leaf? || !self.class.exists?(id) return if right.nil? || left.nil? || leaf? || !self.class.exists?(id)
delete_method = acts_as_nested_set_options[:dependent] == :destroy ?
:destroy_all : :delete_all
# TODO: should destroy children (not descendants) when deleted_method is :destroy_all
self.class.base_class.transaction do self.class.base_class.transaction do
reload_nested_set reload_nested_set
nested_set_scope.send(delete_method, if acts_as_nested_set_options[:dependent] == :destroy
["#{quoted_left_column_name} > ? AND #{quoted_right_column_name} < ?", children.each(&:destroy)
left, right] else
) nested_set_scope.send(:delete_all,
["#{quoted_left_column_name} > ? AND #{quoted_right_column_name} < ?",
left, right]
)
end
reload_nested_set reload_nested_set
diff = right - left + 1 diff = right - left + 1
nested_set_scope.update_all( nested_set_scope.update_all(