##// END OF EJS Templates
Fixed: Error deleting issue with grandchild (#8880)....
Jean-Philippe Lang -
r6191:9957883c4ddf
parent child
Show More
@@ -252,6 +252,20 class IssueNestedSetTest < ActiveSupport::TestCase
252 root = Issue.find(root.id)
252 root = Issue.find(root.id)
253 assert root.leaf?, "Root issue is not a leaf (lft: #{root.lft}, rgt: #{root.rgt})"
253 assert root.leaf?, "Root issue is not a leaf (lft: #{root.lft}, rgt: #{root.rgt})"
254 end
254 end
255
256 def test_destroy_issue_with_grand_child
257 parent = create_issue!
258 issue = create_issue!(:parent_issue_id => parent.id)
259 child = create_issue!(:parent_issue_id => issue.id)
260 grandchild1 = create_issue!(:parent_issue_id => child.id)
261 grandchild2 = create_issue!(:parent_issue_id => child.id)
262
263 assert_difference 'Issue.count', -4 do
264 Issue.find(issue.id).destroy
265 parent.reload
266 assert_equal [1, 2], [parent.lft, parent.rgt]
267 end
268 end
255
269
256 def test_parent_priority_should_be_the_highest_child_priority
270 def test_parent_priority_should_be_the_highest_child_priority
257 parent = create_issue!(:priority => IssuePriority.find_by_name('Normal'))
271 parent = create_issue!(:priority => IssuePriority.find_by_name('Normal'))
@@ -446,16 +446,16 module CollectiveIdea #:nodoc:
446 def prune_from_tree
446 def prune_from_tree
447 return if right.nil? || left.nil? || leaf? || !self.class.exists?(id)
447 return if right.nil? || left.nil? || leaf? || !self.class.exists?(id)
448
448
449 delete_method = acts_as_nested_set_options[:dependent] == :destroy ?
450 :destroy_all : :delete_all
451
452 # TODO: should destroy children (not descendants) when deleted_method is :destroy_all
453 self.class.base_class.transaction do
449 self.class.base_class.transaction do
454 reload_nested_set
450 reload_nested_set
455 nested_set_scope.send(delete_method,
451 if acts_as_nested_set_options[:dependent] == :destroy
456 ["#{quoted_left_column_name} > ? AND #{quoted_right_column_name} < ?",
452 children.each(&:destroy)
457 left, right]
453 else
458 )
454 nested_set_scope.send(:delete_all,
455 ["#{quoted_left_column_name} > ? AND #{quoted_right_column_name} < ?",
456 left, right]
457 )
458 end
459 reload_nested_set
459 reload_nested_set
460 diff = right - left + 1
460 diff = right - left + 1
461 nested_set_scope.update_all(
461 nested_set_scope.update_all(
General Comments 0
You need to be logged in to leave comments. Login now