Commit 682c1e9f authored by jplang's avatar jplang
Browse files

Make the 'duplicates of' relation asymmetric:

* closing a issue will close its duplicates
* closing a duplicate won't close the main issue

git-svn-id: https://svn.redmine.org/redmine/trunk@1488 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 58f80fd7
......@@ -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
......
......@@ -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
......
......@@ -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))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment