@@ -17,8 +17,10 | |||
|
17 | 17 | |
|
18 | 18 | class IssueStatus < ActiveRecord::Base |
|
19 | 19 | before_destroy :check_integrity |
|
20 |
has_many :workflows, :foreign_key => "old_status_id" |
|
|
20 | has_many :workflows, :foreign_key => "old_status_id" | |
|
21 | 21 | acts_as_list |
|
22 | ||
|
23 | before_destroy :delete_workflows | |
|
22 | 24 | |
|
23 | 25 | validates_presence_of :name |
|
24 | 26 | validates_uniqueness_of :name |
@@ -89,4 +91,9 private | |||
|
89 | 91 | def check_integrity |
|
90 | 92 | raise "Can't delete status" if Issue.find(:first, :conditions => ["status_id=?", self.id]) |
|
91 | 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 | 99 | end |
@@ -32,10 +32,12 class IssueStatusTest < ActiveSupport::TestCase | |||
|
32 | 32 | end |
|
33 | 33 | |
|
34 | 34 | def test_destroy |
|
35 | count_before = IssueStatus.count | |
|
36 | 35 | status = IssueStatus.find(3) |
|
37 | assert status.destroy | |
|
38 | assert_equal count_before - 1, IssueStatus.count | |
|
36 | assert_difference 'IssueStatus.count', -1 do | |
|
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 | 41 | end |
|
40 | 42 | |
|
41 | 43 | def test_destroy_status_in_use |
General Comments 0
You need to be logged in to leave comments.
Login now