diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-10-29 10:06:30 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-10-29 10:06:30 +0000 |
commit | b71355f10b247f35a32fc002d52a9ca536537998 (patch) | |
tree | 02618fb61aedd65e713ae699915b39391dd09f79 /test/unit | |
parent | 48d83884c36fae4882061360da25f4e2ed1def13 (diff) | |
download | redmine-b71355f10b247f35a32fc002d52a9ca536537998.tar.gz redmine-b71355f10b247f35a32fc002d52a9ca536537998.zip |
Ignore non-working days when rescheduling an issue (#2161).
Weekly non-working days can be configured in application settings (set to saturday and sunday by default).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10747 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/issue_nested_set_test.rb | 2 | ||||
-rw-r--r-- | test/unit/issue_test.rb | 83 | ||||
-rw-r--r-- | test/unit/lib/redmine/utils/date_calculation.rb | 76 |
3 files changed, 148 insertions, 13 deletions
diff --git a/test/unit/issue_nested_set_test.rb b/test/unit/issue_nested_set_test.rb index c5513f922..d796edf94 100644 --- a/test/unit/issue_nested_set_test.rb +++ b/test/unit/issue_nested_set_test.rb @@ -346,7 +346,7 @@ class IssueNestedSetTest < ActiveSupport::TestCase c1 = Issue.generate!(:start_date => '2010-05-12', :due_date => '2010-05-18', :parent_issue_id => parent.id) c2 = Issue.generate!(:start_date => '2010-06-03', :due_date => '2010-06-10', :parent_issue_id => parent.id) parent.reload - parent.reschedule_after(Date.parse('2010-06-02')) + parent.reschedule_on!(Date.parse('2010-06-02')) c1.reload assert_equal [Date.parse('2010-06-02'), Date.parse('2010-06-08')], [c1.start_date, c1.due_date] c2.reload diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index 15e79bec4..1be4c02b6 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -1300,22 +1300,81 @@ class IssueTest < ActiveSupport::TestCase assert !closed_statuses.empty? end + def test_reschedule_an_issue_without_dates + with_settings :non_working_week_days => [] do + issue = Issue.new(:start_date => nil, :due_date => nil) + issue.reschedule_on '2012-10-09'.to_date + assert_equal '2012-10-09'.to_date, issue.start_date + assert_equal '2012-10-09'.to_date, issue.due_date + end + + with_settings :non_working_week_days => %w(6 7) do + issue = Issue.new(:start_date => nil, :due_date => nil) + issue.reschedule_on '2012-10-09'.to_date + assert_equal '2012-10-09'.to_date, issue.start_date + assert_equal '2012-10-09'.to_date, issue.due_date + + issue = Issue.new(:start_date => nil, :due_date => nil) + issue.reschedule_on '2012-10-13'.to_date + assert_equal '2012-10-15'.to_date, issue.start_date + assert_equal '2012-10-15'.to_date, issue.due_date + end + end + + def test_reschedule_an_issue_with_start_date + with_settings :non_working_week_days => [] do + issue = Issue.new(:start_date => '2012-10-09', :due_date => nil) + issue.reschedule_on '2012-10-13'.to_date + assert_equal '2012-10-13'.to_date, issue.start_date + assert_equal '2012-10-13'.to_date, issue.due_date + end + + with_settings :non_working_week_days => %w(6 7) do + issue = Issue.new(:start_date => '2012-10-09', :due_date => nil) + issue.reschedule_on '2012-10-11'.to_date + assert_equal '2012-10-11'.to_date, issue.start_date + assert_equal '2012-10-11'.to_date, issue.due_date + + issue = Issue.new(:start_date => '2012-10-09', :due_date => nil) + issue.reschedule_on '2012-10-13'.to_date + assert_equal '2012-10-15'.to_date, issue.start_date + assert_equal '2012-10-15'.to_date, issue.due_date + end + end + + def test_reschedule_an_issue_with_start_and_due_dates + with_settings :non_working_week_days => [] do + issue = Issue.new(:start_date => '2012-10-09', :due_date => '2012-10-15') + issue.reschedule_on '2012-10-13'.to_date + assert_equal '2012-10-13'.to_date, issue.start_date + assert_equal '2012-10-19'.to_date, issue.due_date + end + + with_settings :non_working_week_days => %w(6 7) do + issue = Issue.new(:start_date => '2012-10-09', :due_date => '2012-10-19') # 8 working days + issue.reschedule_on '2012-10-11'.to_date + assert_equal '2012-10-11'.to_date, issue.start_date + assert_equal '2012-10-23'.to_date, issue.due_date + + issue = Issue.new(:start_date => '2012-10-09', :due_date => '2012-10-19') + issue.reschedule_on '2012-10-13'.to_date + assert_equal '2012-10-15'.to_date, issue.start_date + assert_equal '2012-10-25'.to_date, issue.due_date + end + end + def test_rescheduling_an_issue_should_reschedule_following_issue - issue1 = Issue.create!(:project_id => 1, :tracker_id => 1, - :author_id => 1, :status_id => 1, - :subject => '-', - :start_date => Date.today, :due_date => Date.today + 2) - issue2 = Issue.create!(:project_id => 1, :tracker_id => 1, - :author_id => 1, :status_id => 1, - :subject => '-', - :start_date => Date.today, :due_date => Date.today + 2) + 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 issue1.due_date + 1, issue2.reload.start_date + assert_equal Date.parse('2012-10-18'), issue2.reload.start_date - issue1.due_date = Date.today + 5 + issue1.due_date = '2012-10-23' issue1.save! - assert_equal issue1.due_date + 1, issue2.reload.start_date + issue2.reload + assert_equal Date.parse('2012-10-24'), issue2.start_date + assert_equal Date.parse('2012-10-26'), issue2.due_date end def test_rescheduling_a_stale_issue_should_not_raise_an_error @@ -1326,7 +1385,7 @@ class IssueTest < ActiveSupport::TestCase date = 10.days.from_now.to_date assert_nothing_raised do - stale.reschedule_after(date) + stale.reschedule_on!(date) end assert_equal date, stale.reload.start_date end diff --git a/test/unit/lib/redmine/utils/date_calculation.rb b/test/unit/lib/redmine/utils/date_calculation.rb new file mode 100644 index 000000000..6cd904969 --- /dev/null +++ b/test/unit/lib/redmine/utils/date_calculation.rb @@ -0,0 +1,76 @@ +# Redmine - project management software +# Copyright (C) 2006-2012 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require File.expand_path('../../../../../test_helper', __FILE__) + +class Redmine::Utils::DateCalculationTest < ActiveSupport::TestCase + include Redmine::Utils::DateCalculation + + def test_working_days_without_non_working_week_days + with_settings :non_working_week_days => [] do + assert_working_days 18, '2012-10-09', '2012-10-27' + assert_working_days 6, '2012-10-09', '2012-10-15' + assert_working_days 5, '2012-10-09', '2012-10-14' + assert_working_days 3, '2012-10-09', '2012-10-12' + assert_working_days 3, '2012-10-14', '2012-10-17' + assert_working_days 16, '2012-10-14', '2012-10-30' + end + end + + def test_working_days_with_non_working_week_days + with_settings :non_working_week_days => %w(6 7) do + assert_working_days 14, '2012-10-09', '2012-10-27' + assert_working_days 4, '2012-10-09', '2012-10-15' + assert_working_days 4, '2012-10-09', '2012-10-14' + assert_working_days 3, '2012-10-09', '2012-10-12' + assert_working_days 8, '2012-10-09', '2012-10-19' + assert_working_days 8, '2012-10-11', '2012-10-23' + assert_working_days 2, '2012-10-14', '2012-10-17' + assert_working_days 11, '2012-10-14', '2012-10-30' + end + end + + def test_add_working_days_without_non_working_week_days + with_settings :non_working_week_days => [] do + assert_add_working_days '2012-10-10', '2012-10-10', 0 + assert_add_working_days '2012-10-11', '2012-10-10', 1 + assert_add_working_days '2012-10-12', '2012-10-10', 2 + assert_add_working_days '2012-10-13', '2012-10-10', 3 + assert_add_working_days '2012-10-25', '2012-10-10', 15 + end + end + + def test_add_working_days_with_non_working_week_days + with_settings :non_working_week_days => %w(6 7) do + assert_add_working_days '2012-10-10', '2012-10-10', 0 + assert_add_working_days '2012-10-11', '2012-10-10', 1 + assert_add_working_days '2012-10-12', '2012-10-10', 2 + assert_add_working_days '2012-10-15', '2012-10-10', 3 + assert_add_working_days '2012-10-31', '2012-10-10', 15 + assert_add_working_days '2012-10-19', '2012-10-09', 8 + assert_add_working_days '2012-10-23', '2012-10-11', 8 + end + end + + def assert_working_days(expected_days, from, to) + assert_equal expected_days, working_days(from.to_date, to.to_date) + end + + def assert_add_working_days(expected_date, from, working_days) + assert_equal expected_date.to_date, add_working_days(from.to_date, working_days) + end +end |