diff --git a/app/models/issue.rb b/app/models/issue.rb index 633253db..d83b2ab0 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -225,9 +225,9 @@ class Issue < ActiveRecord::Base dependencies end - # Returns an array of the duplicate issues + # Returns an array of issues that duplicate this one def duplicates - relations.select {|r| r.relation_type == IssueRelation::TYPE_DUPLICATES}.collect {|r| r.other_issue(self)} + relations_to.select {|r| r.relation_type == IssueRelation::TYPE_DUPLICATES}.collect {|r| r.issue_from} end # Returns the due date or the target due date if any diff --git a/app/models/issue_relation.rb b/app/models/issue_relation.rb index 07e940b8..49329e0b 100644 --- a/app/models/issue_relation.rb +++ b/app/models/issue_relation.rb @@ -25,7 +25,7 @@ class IssueRelation < ActiveRecord::Base TYPE_PRECEDES = "precedes" TYPES = { TYPE_RELATES => { :name => :label_relates_to, :sym_name => :label_relates_to, :order => 1 }, - TYPE_DUPLICATES => { :name => :label_duplicates, :sym_name => :label_duplicates, :order => 2 }, + TYPE_DUPLICATES => { :name => :label_duplicates, :sym_name => :label_duplicated_by, :order => 2 }, TYPE_BLOCKS => { :name => :label_blocks, :sym_name => :label_blocked_by, :order => 3 }, TYPE_PRECEDES => { :name => :label_precedes, :sym_name => :label_follows, :order => 4 }, }.freeze diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index 36ba1fb4..999c4480 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -42,7 +42,7 @@ class IssueTest < Test::Unit::TestCase assert_equal orig.custom_values.first.value, issue.custom_values.first.value end - def test_close_duplicates + def test_should_close_duplicates # Create 3 issues 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') assert issue1.save @@ -52,12 +52,12 @@ class IssueTest < Test::Unit::TestCase assert issue3.save # 2 is a dupe of 1 - IssueRelation.create(:issue_from => issue1, :issue_to => issue2, :relation_type => IssueRelation::TYPE_DUPLICATES) + IssueRelation.create(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) # And 3 is a dupe of 2 - IssueRelation.create(:issue_from => issue2, :issue_to => issue3, :relation_type => IssueRelation::TYPE_DUPLICATES) + IssueRelation.create(:issue_from => issue3, :issue_to => issue2, :relation_type => IssueRelation::TYPE_DUPLICATES) # And 3 is a dupe of 1 (circular duplicates) - IssueRelation.create(:issue_from => issue1, :issue_to => issue3, :relation_type => IssueRelation::TYPE_DUPLICATES) - + IssueRelation.create(:issue_from => issue3, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) + assert issue1.reload.duplicates.include?(issue2) # Closing issue 1 @@ -69,6 +69,26 @@ class IssueTest < Test::Unit::TestCase assert issue3.reload.closed? end + def test_should_not_close_duplicated_issue + # Create 3 issues + 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') + assert issue1.save + issue2 = issue1.clone + assert issue2.save + + # 2 is a dupe of 1 + IssueRelation.create(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) + # 2 is a dup of 1 but 1 is not a duplicate of 2 + assert !issue2.reload.duplicates.include?(issue1) + + # Closing issue 2 + issue2.init_journal(User.find(:first), "Closing issue2") + issue2.status = IssueStatus.find :first, :conditions => {:is_closed => true} + assert issue2.save + # 1 should not be also closed + assert !issue1.reload.closed? + end + def test_move_to_another_project issue = Issue.find(1) assert issue.move_to(Project.find(2))