]> source.dussan.org Git - redmine.git/commitdiff
Fixed: Error deleting issue with grandchild (#8880).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 24 Jul 2011 08:35:48 +0000 (08:35 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 24 Jul 2011 08:35:48 +0000 (08:35 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@6311 e93f8b46-1217-0410-a6f0-8f06a7374b81

test/unit/issue_nested_set_test.rb
vendor/plugins/awesome_nested_set/lib/awesome_nested_set.rb

index 6cbc44461280267adaccf543010d126d69d4c91f..103787a0070dda4213c708d8e82bf34032f29416 100644 (file)
@@ -252,6 +252,20 @@ class IssueNestedSetTest < ActiveSupport::TestCase
     root = Issue.find(root.id)
     assert root.leaf?, "Root issue is not a leaf (lft: #{root.lft}, rgt: #{root.rgt})"
   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
     parent = create_issue!(:priority => IssuePriority.find_by_name('Normal'))
index f46fb4335438a2f665711bcf5a8c3b62d41962b3..fcf00b3c3dcc9a22105aeb09ed31af1d67b2120a 100644 (file)
@@ -446,16 +446,16 @@ module CollectiveIdea #:nodoc:
         def prune_from_tree
           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
             reload_nested_set
-            nested_set_scope.send(delete_method,
-              ["#{quoted_left_column_name} > ? AND #{quoted_right_column_name} < ?",
-                left, right]
-            )
+            if acts_as_nested_set_options[:dependent] == :destroy
+              children.each(&:destroy)
+            else
+              nested_set_scope.send(:delete_all,
+                ["#{quoted_left_column_name} > ? AND #{quoted_right_column_name} < ?",
+                  left, right]
+              )
+            end
             reload_nested_set
             diff = right - left + 1
             nested_set_scope.update_all(