]> source.dussan.org Git - redmine.git/commitdiff
Fixed: bulk destroying parent and child issues raises a stale object error (#7920).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 1 Apr 2011 16:26:53 +0000 (16:26 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 1 Apr 2011 16:26:53 +0000 (16:26 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5283 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/issues_controller.rb
test/functional/issues_controller_test.rb

index f51188fcc974ce4a507ced887ebfb137203fe315..fdce296c44203956880988bfc8435c9b495ad03e 100644 (file)
@@ -236,7 +236,13 @@ class IssuesController < ApplicationController
         return unless api_request?
       end
     end
-    @issues.each(&:destroy)
+    @issues.each do |issue|
+      begin
+        issue.reload.destroy
+      rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists
+        # nothing to do, issue was already deleted (eg. by a parent)
+      end
+    end
     respond_to do |format|
       format.html { redirect_back_or_default(:action => 'index', :project_id => @project) }
       format.api  { head :ok }
index ed81597da7211fbf3560da842eb917973a81e254..da25ac06305065605df33a29de63e39dc719fc15 100644 (file)
@@ -1323,6 +1323,18 @@ class IssuesControllerTest < ActionController::TestCase
     assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6))
   end
   
+  def test_destroy_parent_and_child_issues
+    parent = Issue.generate!(:project_id => 1, :tracker_id => 1)
+    child = Issue.generate!(:project_id => 1, :tracker_id => 1, :parent_issue_id => parent.id)
+    assert child.is_descendant_of?(parent.reload)
+    
+    @request.session[:user_id] = 2
+    assert_difference 'Issue.count', -2 do
+      post :destroy, :ids => [parent.id, child.id], :todo => 'destroy'
+    end
+    assert_response 302
+  end
+  
   def test_default_search_scope
     get :index
     assert_tag :div, :attributes => {:id => 'quick-search'},