@@ -225,9 +225,9 class Issue < ActiveRecord::Base | |||
|
225 | 225 | dependencies |
|
226 | 226 | end |
|
227 | 227 | |
|
228 |
# Returns an array of |
|
|
228 | # Returns an array of issues that duplicate this one | |
|
229 | 229 | def duplicates |
|
230 |
relations.select {|r| r.relation_type == IssueRelation::TYPE_DUPLICATES}.collect {|r| r. |
|
|
230 | relations_to.select {|r| r.relation_type == IssueRelation::TYPE_DUPLICATES}.collect {|r| r.issue_from} | |
|
231 | 231 | end |
|
232 | 232 | |
|
233 | 233 | # Returns the due date or the target due date if any |
@@ -25,7 +25,7 class IssueRelation < ActiveRecord::Base | |||
|
25 | 25 | TYPE_PRECEDES = "precedes" |
|
26 | 26 | |
|
27 | 27 | TYPES = { TYPE_RELATES => { :name => :label_relates_to, :sym_name => :label_relates_to, :order => 1 }, |
|
28 |
TYPE_DUPLICATES => { :name => :label_duplicates, :sym_name => :label_duplicate |
|
|
28 | TYPE_DUPLICATES => { :name => :label_duplicates, :sym_name => :label_duplicated_by, :order => 2 }, | |
|
29 | 29 | TYPE_BLOCKS => { :name => :label_blocks, :sym_name => :label_blocked_by, :order => 3 }, |
|
30 | 30 | TYPE_PRECEDES => { :name => :label_precedes, :sym_name => :label_follows, :order => 4 }, |
|
31 | 31 | }.freeze |
@@ -42,7 +42,7 class IssueTest < Test::Unit::TestCase | |||
|
42 | 42 | assert_equal orig.custom_values.first.value, issue.custom_values.first.value |
|
43 | 43 | end |
|
44 | 44 | |
|
45 | def test_close_duplicates | |
|
45 | def test_should_close_duplicates | |
|
46 | 46 | # Create 3 issues |
|
47 | 47 | 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') |
|
48 | 48 | assert issue1.save |
@@ -52,12 +52,12 class IssueTest < Test::Unit::TestCase | |||
|
52 | 52 | assert issue3.save |
|
53 | 53 | |
|
54 | 54 | # 2 is a dupe of 1 |
|
55 |
IssueRelation.create(:issue_from => issue |
|
|
55 | IssueRelation.create(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) | |
|
56 | 56 | # And 3 is a dupe of 2 |
|
57 |
IssueRelation.create(:issue_from => issue |
|
|
57 | IssueRelation.create(:issue_from => issue3, :issue_to => issue2, :relation_type => IssueRelation::TYPE_DUPLICATES) | |
|
58 | 58 | # And 3 is a dupe of 1 (circular duplicates) |
|
59 |
IssueRelation.create(:issue_from => issue |
|
|
60 | ||
|
59 | IssueRelation.create(:issue_from => issue3, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) | |
|
60 | ||
|
61 | 61 | assert issue1.reload.duplicates.include?(issue2) |
|
62 | 62 | |
|
63 | 63 | # Closing issue 1 |
@@ -69,6 +69,26 class IssueTest < Test::Unit::TestCase | |||
|
69 | 69 | assert issue3.reload.closed? |
|
70 | 70 | end |
|
71 | 71 | |
|
72 | def test_should_not_close_duplicated_issue | |
|
73 | # Create 3 issues | |
|
74 | 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') | |
|
75 | assert issue1.save | |
|
76 | issue2 = issue1.clone | |
|
77 | assert issue2.save | |
|
78 | ||
|
79 | # 2 is a dupe of 1 | |
|
80 | IssueRelation.create(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) | |
|
81 | # 2 is a dup of 1 but 1 is not a duplicate of 2 | |
|
82 | assert !issue2.reload.duplicates.include?(issue1) | |
|
83 | ||
|
84 | # Closing issue 2 | |
|
85 | issue2.init_journal(User.find(:first), "Closing issue2") | |
|
86 | issue2.status = IssueStatus.find :first, :conditions => {:is_closed => true} | |
|
87 | assert issue2.save | |
|
88 | # 1 should not be also closed | |
|
89 | assert !issue1.reload.closed? | |
|
90 | end | |
|
91 | ||
|
72 | 92 | def test_move_to_another_project |
|
73 | 93 | issue = Issue.find(1) |
|
74 | 94 | assert issue.move_to(Project.find(2)) |
General Comments 0
You need to be logged in to leave comments.
Login now