14846.patch

Felix Schäfer, 2014-03-10 23:11

Download (3.25 KB)

View differences:

app/models/issue_relation.rb
30 30
    end
31 31
  end
32 32

  
33
  include Redmine::Utils::DateCalculation
34

  
33 35
  belongs_to :issue_from, :class_name => 'Issue', :foreign_key => 'issue_from_id'
34 36
  belongs_to :issue_to, :class_name => 'Issue', :foreign_key => 'issue_to_id'
35 37

  
......
159 161
  def successor_soonest_start
160 162
    if (TYPE_PRECEDES == self.relation_type) && delay && issue_from &&
161 163
           (issue_from.start_date || issue_from.due_date)
162
      (issue_from.due_date || issue_from.start_date) + 1 + delay
164
      add_working_days((issue_from.due_date || issue_from.start_date), (1 + delay))
163 165
    end
164 166
  end
165 167

  
test/unit/issue_test.rb
1514 1514
  end
1515 1515

  
1516 1516
  def test_rescheduling_an_issue_to_a_later_due_date_should_reschedule_following_issue
1517
    issue1 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17')
1518
    issue2 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17')
1519
    IssueRelation.create!(:issue_from => issue1, :issue_to => issue2,
1520
                          :relation_type => IssueRelation::TYPE_PRECEDES)
1521
    assert_equal Date.parse('2012-10-18'), issue2.reload.start_date
1517
    with_settings :non_working_week_days => [] do
1518
      issue1 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17')
1519
      issue2 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17')
1520
      IssueRelation.create!(:issue_from => issue1, :issue_to => issue2,
1521
                            :relation_type => IssueRelation::TYPE_PRECEDES)
1522
      assert_equal Date.parse('2012-10-18'), issue2.reload.start_date
1523

  
1524
      issue1.reload
1525
      issue1.due_date = '2012-10-23'
1526
      issue1.save!
1527
      issue2.reload
1528
      assert_equal Date.parse('2012-10-24'), issue2.start_date
1529
      assert_equal Date.parse('2012-10-26'), issue2.due_date
1530
    end
1522 1531

  
1523
    issue1.reload
1524
    issue1.due_date = '2012-10-23'
1525
    issue1.save!
1526
    issue2.reload
1527
    assert_equal Date.parse('2012-10-24'), issue2.start_date
1528
    assert_equal Date.parse('2012-10-26'), issue2.due_date
1532
    # The delay should honor non-working week days
1533
    with_settings :non_working_week_days => %w(6 7) do
1534
      issue1 = Issue.generate!(:start_date => '2014-03-10', :due_date => '2014-03-12')
1535
      issue2 = Issue.generate!(:start_date => '2014-03-10', :due_date => '2014-03-12')
1536
      IssueRelation.create!(:issue_from => issue1, :issue_to => issue2,
1537
                            :relation_type => IssueRelation::TYPE_PRECEDES,
1538
                            :delay => 8)
1539
      assert_equal Date.parse('2014-03-25'), issue2.reload.start_date
1540
    end
1529 1541
  end
1530 1542

  
1531 1543
  def test_rescheduling_an_issue_to_an_earlier_due_date_should_reschedule_following_issue