@@ -94,7 +94,19 class Issue < ActiveRecord::Base | |||
|
94 | 94 | end |
|
95 | 95 | |
|
96 | 96 | def after_save |
|
97 | # Update start/due dates of following issues | |
|
97 | 98 | relations_from.each(&:set_issue_to_dates) |
|
99 | ||
|
100 | # Close duplicates if the issue was closed | |
|
101 | if @issue_before_change && !@issue_before_change.closed? && self.closed? | |
|
102 | duplicates.each do |duplicate| | |
|
103 | # Don't re-close it if it's already closed | |
|
104 | next if duplicate.closed? | |
|
105 | # Same user and notes | |
|
106 | duplicate.init_journal(@current_journal.user, @current_journal.notes) | |
|
107 | duplicate.update_attribute :status, self.status | |
|
108 | end | |
|
109 | end | |
|
98 | 110 | end |
|
99 | 111 | |
|
100 | 112 | def custom_value_for(custom_field) |
@@ -110,6 +122,11 class Issue < ActiveRecord::Base | |||
|
110 | 122 | @current_journal |
|
111 | 123 | end |
|
112 | 124 | |
|
125 | # Return true if the issue is closed, otherwise false | |
|
126 | def closed? | |
|
127 | self.status.is_closed? | |
|
128 | end | |
|
129 | ||
|
113 | 130 | # Users the issue can be assigned to |
|
114 | 131 | def assignable_users |
|
115 | 132 | project.members.select {|m| m.role.assignable?}.collect {|m| m.user} |
@@ -132,6 +149,11 class Issue < ActiveRecord::Base | |||
|
132 | 149 | dependencies |
|
133 | 150 | end |
|
134 | 151 | |
|
152 | # Returns an array of the duplicate issues | |
|
153 | def duplicates | |
|
154 | relations.select {|r| r.relation_type == IssueRelation::TYPE_DUPLICATES}.collect {|r| r.other_issue(self)} | |
|
155 | end | |
|
156 | ||
|
135 | 157 | def duration |
|
136 | 158 | (start_date && due_date) ? due_date - start_date : 0 |
|
137 | 159 | end |
@@ -24,4 +24,29 class IssueTest < Test::Unit::TestCase | |||
|
24 | 24 | issue = Issue.create(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => Enumeration.get_values('IPRI').first, :subject => 'Assignment test', :description => 'Assignment test', :category_id => 1) |
|
25 | 25 | assert_equal IssueCategory.find(1).assigned_to, issue.assigned_to |
|
26 | 26 | end |
|
27 | ||
|
28 | def test_close_duplicates | |
|
29 | # Create 3 issues | |
|
30 | issue1 = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :priority => Enumeration.get_values('IPRI').first, :subject => 'Duplicates test', :description => 'Duplicates test') | |
|
31 | assert issue1.save | |
|
32 | issue2 = issue1.clone | |
|
33 | assert issue2.save | |
|
34 | issue3 = issue1.clone | |
|
35 | assert issue3.save | |
|
36 | ||
|
37 | # 2 is a dupe of 1 | |
|
38 | IssueRelation.create(:issue_from => issue1, :issue_to => issue2, :relation_type => IssueRelation::TYPE_DUPLICATES) | |
|
39 | # And 3 is a dupe of 2 | |
|
40 | IssueRelation.create(:issue_from => issue2, :issue_to => issue3, :relation_type => IssueRelation::TYPE_DUPLICATES) | |
|
41 | ||
|
42 | assert issue1.reload.duplicates.include?(issue2) | |
|
43 | ||
|
44 | # Closing issue 1 | |
|
45 | issue1.init_journal(User.find(:first), "Closing issue1") | |
|
46 | issue1.status = IssueStatus.find :first, :conditions => {:is_closed => true} | |
|
47 | assert issue1.save | |
|
48 | # 2 and 3 should be also closed | |
|
49 | assert issue2.reload.closed? | |
|
50 | assert issue3.reload.closed? | |
|
51 | end | |
|
27 | 52 | end |
General Comments 0
You need to be logged in to leave comments.
Login now