From c47d23a87be4e9de873d57ec2b843e8e7efc2caa Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 25 Jul 2010 10:48:27 +0000 Subject: [PATCH] Fixed: Deleting statuses doesn't delete all workflow entries (#5811). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3881 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/issue_status.rb | 9 ++++++++- test/unit/issue_status_test.rb | 8 +++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/models/issue_status.rb b/app/models/issue_status.rb index fdda12a8c..f376d5d15 100644 --- a/app/models/issue_status.rb +++ b/app/models/issue_status.rb @@ -17,8 +17,10 @@ class IssueStatus < ActiveRecord::Base before_destroy :check_integrity - has_many :workflows, :foreign_key => "old_status_id", :dependent => :delete_all + has_many :workflows, :foreign_key => "old_status_id" acts_as_list + + before_destroy :delete_workflows validates_presence_of :name validates_uniqueness_of :name @@ -89,4 +91,9 @@ private def check_integrity raise "Can't delete status" if Issue.find(:first, :conditions => ["status_id=?", self.id]) end + + # Deletes associated workflows + def delete_workflows + Workflow.delete_all(["old_status_id = :id OR new_status_id = :id", {:id => id}]) + end end diff --git a/test/unit/issue_status_test.rb b/test/unit/issue_status_test.rb index 2c0685cec..bcc50a480 100644 --- a/test/unit/issue_status_test.rb +++ b/test/unit/issue_status_test.rb @@ -32,10 +32,12 @@ class IssueStatusTest < ActiveSupport::TestCase end def test_destroy - count_before = IssueStatus.count status = IssueStatus.find(3) - assert status.destroy - assert_equal count_before - 1, IssueStatus.count + assert_difference 'IssueStatus.count', -1 do + assert status.destroy + end + assert_nil Workflow.first(:conditions => {:old_status_id => status.id}) + assert_nil Workflow.first(:conditions => {:new_status_id => status.id}) end def test_destroy_status_in_use