From b94c971755ec0de932cb55ed5b813bbb033b6141 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 24 Nov 2012 13:43:52 +0000 Subject: [PATCH] Precede-Follow relation should move following issues earlier when rescheduling issue earlier (#4590). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10878 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/issue.rb | 11 ++++++++--- test/unit/issue_test.rb | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index 119d688c7..f591f778b 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -869,9 +869,10 @@ class Issue < ActiveRecord::Base (start_date && due_date) ? working_days(start_date, due_date) : 0 end - def soonest_start + def soonest_start(reload=false) + @soonest_start = nil if reload @soonest_start ||= ( - relations_to.collect{|relation| relation.successor_soonest_start} + + relations_to(reload).collect{|relation| relation.successor_soonest_start} + ancestors.collect(&:soonest_start) ).compact.max end @@ -890,7 +891,11 @@ class Issue < ActiveRecord::Base def reschedule_on!(date) return if date.nil? if leaf? - if start_date.nil? || start_date < date + if start_date.nil? || start_date != date + if start_date && start_date > date + # Issue can not be moved earlier than its soonest start date + date = [soonest_start(true), date].compact.max + end reschedule_on(date) begin save diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index a5ab9aa72..655edb53c 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -1363,7 +1363,7 @@ class IssueTest < ActiveSupport::TestCase end end - def test_rescheduling_an_issue_should_reschedule_following_issue + def test_rescheduling_an_issue_to_a_later_due_date_should_reschedule_following_issue issue1 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17') issue2 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17') IssueRelation.create!(:issue_from => issue1, :issue_to => issue2, @@ -1377,6 +1377,40 @@ class IssueTest < ActiveSupport::TestCase assert_equal Date.parse('2012-10-26'), issue2.due_date end + def test_rescheduling_an_issue_to_an_earlier_due_date_should_reschedule_following_issue + issue1 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17') + issue2 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17') + IssueRelation.create!(:issue_from => issue1, :issue_to => issue2, + :relation_type => IssueRelation::TYPE_PRECEDES) + assert_equal Date.parse('2012-10-18'), issue2.reload.start_date + + issue1.start_date = '2012-09-17' + issue1.due_date = '2012-09-18' + issue1.save! + issue2.reload + assert_equal Date.parse('2012-09-19'), issue2.start_date + assert_equal Date.parse('2012-09-21'), issue2.due_date + end + + def test_rescheduling_reschedule_following_issue_earlier_should_consider_other_preceding_issues + issue1 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17') + issue2 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17') + issue3 = Issue.generate!(:start_date => '2012-10-01', :due_date => '2012-10-02') + IssueRelation.create!(:issue_from => issue1, :issue_to => issue2, + :relation_type => IssueRelation::TYPE_PRECEDES) + IssueRelation.create!(:issue_from => issue3, :issue_to => issue2, + :relation_type => IssueRelation::TYPE_PRECEDES) + assert_equal Date.parse('2012-10-18'), issue2.reload.start_date + + issue1.start_date = '2012-09-17' + issue1.due_date = '2012-09-18' + issue1.save! + issue2.reload + # Issue 2 must start after Issue 3 + assert_equal Date.parse('2012-10-03'), issue2.start_date + assert_equal Date.parse('2012-10-05'), issue2.due_date + end + def test_rescheduling_a_stale_issue_should_not_raise_an_error with_settings :non_working_week_days => [] do stale = Issue.find(1) -- 2.39.5