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
This commit is contained in:
parent
73d9368039
commit
c47d23a87b
|
@ -17,9 +17,11 @@
|
||||||
|
|
||||||
class IssueStatus < ActiveRecord::Base
|
class IssueStatus < ActiveRecord::Base
|
||||||
before_destroy :check_integrity
|
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
|
acts_as_list
|
||||||
|
|
||||||
|
before_destroy :delete_workflows
|
||||||
|
|
||||||
validates_presence_of :name
|
validates_presence_of :name
|
||||||
validates_uniqueness_of :name
|
validates_uniqueness_of :name
|
||||||
validates_length_of :name, :maximum => 30
|
validates_length_of :name, :maximum => 30
|
||||||
|
@ -89,4 +91,9 @@ private
|
||||||
def check_integrity
|
def check_integrity
|
||||||
raise "Can't delete status" if Issue.find(:first, :conditions => ["status_id=?", self.id])
|
raise "Can't delete status" if Issue.find(:first, :conditions => ["status_id=?", self.id])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Deletes associated workflows
|
||||||
|
def delete_workflows
|
||||||
|
Workflow.delete_all(["old_status_id = :id OR new_status_id = :id", {:id => id}])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,10 +32,12 @@ class IssueStatusTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_destroy
|
def test_destroy
|
||||||
count_before = IssueStatus.count
|
|
||||||
status = IssueStatus.find(3)
|
status = IssueStatus.find(3)
|
||||||
|
assert_difference 'IssueStatus.count', -1 do
|
||||||
assert status.destroy
|
assert status.destroy
|
||||||
assert_equal count_before - 1, IssueStatus.count
|
end
|
||||||
|
assert_nil Workflow.first(:conditions => {:old_status_id => status.id})
|
||||||
|
assert_nil Workflow.first(:conditions => {:new_status_id => status.id})
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_destroy_status_in_use
|
def test_destroy_status_in_use
|
||||||
|
|
Loading…
Reference in New Issue