From 7fb0fe2e910a4188db283c359d9b1d05dad99041 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 4 Dec 2010 18:10:02 +0000 Subject: [PATCH] Safer code in IssueRelation (#7018). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4467 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/issue_relation.rb | 7 ++++--- test/unit/issue_relation_test.rb | 10 ++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/models/issue_relation.rb b/app/models/issue_relation.rb index b7959229..8f2db40f 100644 --- a/app/models/issue_relation.rb +++ b/app/models/issue_relation.rb @@ -84,14 +84,15 @@ class IssueRelation < ActiveRecord::Base def set_issue_to_dates soonest_start = self.successor_soonest_start - if soonest_start + if soonest_start && issue_to issue_to.reschedule_after(soonest_start) end end def successor_soonest_start - return nil unless (TYPE_PRECEDES == self.relation_type) && (issue_from.start_date || issue_from.due_date) - (issue_from.due_date || issue_from.start_date) + 1 + delay + if (TYPE_PRECEDES == self.relation_type) && delay && issue_from && (issue_from.start_date || issue_from.due_date) + (issue_from.due_date || issue_from.start_date) + 1 + delay + end end def <=>(relation) diff --git a/test/unit/issue_relation_test.rb b/test/unit/issue_relation_test.rb index 6544c520..f8859dfc 100644 --- a/test/unit/issue_relation_test.rb +++ b/test/unit/issue_relation_test.rb @@ -63,4 +63,14 @@ class IssueRelationTest < ActiveSupport::TestCase assert_equal IssueRelation::TYPE_PRECEDES, relation.relation_type_for(from) assert_equal IssueRelation::TYPE_FOLLOWS, relation.relation_type_for(to) end + + def test_set_issue_to_dates_without_issue_to + r = IssueRelation.new(:issue_from => Issue.new(:start_date => Date.today), :relation_type => IssueRelation::TYPE_PRECEDES, :delay => 1) + assert_nil r.set_issue_to_dates + end + + def test_set_issue_to_dates_without_issues + r = IssueRelation.new(:relation_type => IssueRelation::TYPE_PRECEDES, :delay => 1) + assert_nil r.set_issue_to_dates + end end