##// END OF EJS Templates
Merged r3881 from trunk....
Jean-Philippe Lang -
r3768:52a12aaca884
parent child
Show More
@@ -17,8 +17,10
17
17
18 class IssueStatus < ActiveRecord::Base
18 class IssueStatus < ActiveRecord::Base
19 before_destroy :check_integrity
19 before_destroy :check_integrity
20 has_many :workflows, :foreign_key => "old_status_id", :dependent => :delete_all
20 has_many :workflows, :foreign_key => "old_status_id"
21 acts_as_list
21 acts_as_list
22
23 before_destroy :delete_workflows
22
24
23 validates_presence_of :name
25 validates_presence_of :name
24 validates_uniqueness_of :name
26 validates_uniqueness_of :name
@@ -89,4 +91,9 private
89 def check_integrity
91 def check_integrity
90 raise "Can't delete status" if Issue.find(:first, :conditions => ["status_id=?", self.id])
92 raise "Can't delete status" if Issue.find(:first, :conditions => ["status_id=?", self.id])
91 end
93 end
94
95 # Deletes associated workflows
96 def delete_workflows
97 Workflow.delete_all(["old_status_id = :id OR new_status_id = :id", {:id => id}])
98 end
92 end
99 end
@@ -32,10 +32,12 class IssueStatusTest < ActiveSupport::TestCase
32 end
32 end
33
33
34 def test_destroy
34 def test_destroy
35 count_before = IssueStatus.count
36 status = IssueStatus.find(3)
35 status = IssueStatus.find(3)
37 assert status.destroy
36 assert_difference 'IssueStatus.count', -1 do
38 assert_equal count_before - 1, IssueStatus.count
37 assert status.destroy
38 end
39 assert_nil Workflow.first(:conditions => {:old_status_id => status.id})
40 assert_nil Workflow.first(:conditions => {:new_status_id => status.id})
39 end
41 end
40
42
41 def test_destroy_status_in_use
43 def test_destroy_status_in_use
General Comments 0
You need to be logged in to leave comments. Login now