summaryrefslogtreecommitdiffstats
path: root/test/unit/lib/redmine/utils
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2012-10-29 10:06:30 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2012-10-29 10:06:30 +0000
commitb71355f10b247f35a32fc002d52a9ca536537998 (patch)
tree02618fb61aedd65e713ae699915b39391dd09f79 /test/unit/lib/redmine/utils
parent48d83884c36fae4882061360da25f4e2ed1def13 (diff)
downloadredmine-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/lib/redmine/utils')
-rw-r--r--test/unit/lib/redmine/utils/date_calculation.rb76
1 files changed, 76 insertions, 0 deletions
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