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: http://redmine.rubyforge.org/svn/trunk@1488 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2008-06-03 18:30:29 +00:00
parent 891a71ad47
commit 7042879811
3 changed files with 28 additions and 8 deletions

View File

@ -225,9 +225,9 @@ class Issue < ActiveRecord::Base
dependencies dependencies
end end
# Returns an array of the duplicate issues # Returns an array of issues that duplicate this one
def duplicates 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 end
# Returns the due date or the target due date if any # Returns the due date or the target due date if any

View File

@ -25,7 +25,7 @@ class IssueRelation < ActiveRecord::Base
TYPE_PRECEDES = "precedes" TYPE_PRECEDES = "precedes"
TYPES = { TYPE_RELATES => { :name => :label_relates_to, :sym_name => :label_relates_to, :order => 1 }, 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_BLOCKS => { :name => :label_blocks, :sym_name => :label_blocked_by, :order => 3 },
TYPE_PRECEDES => { :name => :label_precedes, :sym_name => :label_follows, :order => 4 }, TYPE_PRECEDES => { :name => :label_precedes, :sym_name => :label_follows, :order => 4 },
}.freeze }.freeze

View File

@ -42,7 +42,7 @@ class IssueTest < Test::Unit::TestCase
assert_equal orig.custom_values.first.value, issue.custom_values.first.value assert_equal orig.custom_values.first.value, issue.custom_values.first.value
end end
def test_close_duplicates def test_should_close_duplicates
# Create 3 issues # 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') 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 assert issue1.save
@ -52,11 +52,11 @@ class IssueTest < Test::Unit::TestCase
assert issue3.save assert issue3.save
# 2 is a dupe of 1 # 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 # 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) # 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) assert issue1.reload.duplicates.include?(issue2)
@ -69,6 +69,26 @@ class IssueTest < Test::Unit::TestCase
assert issue3.reload.closed? assert issue3.reload.closed?
end 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 def test_move_to_another_project
issue = Issue.find(1) issue = Issue.find(1)
assert issue.move_to(Project.find(2)) assert issue.move_to(Project.find(2))