summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2015-05-25 09:53:05 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2015-05-25 09:53:05 +0000
commit0ad09e3aef86d4e6c6784d5d906bfa6d1767757f (patch)
treec626a05d630f6529294dbf6a8065f17a235f3256 /test
parent09b935b44ed897afc3f0abcc614558bf6356b6ba (diff)
downloadredmine-0ad09e3aef86d4e6c6784d5d906bfa6d1767757f.tar.gz
redmine-0ad09e3aef86d4e6c6784d5d906bfa6d1767757f.zip
Adds settings to control start/due dates and priority on parent tasks (#5490).
git-svn-id: http://svn.redmine.org/redmine/trunk@14269 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test')
-rw-r--r--test/object_helpers.rb6
-rw-r--r--test/unit/issue_nested_set_test.rb43
-rw-r--r--test/unit/issue_subtasking_test.rb146
3 files changed, 152 insertions, 43 deletions
diff --git a/test/object_helpers.rb b/test/object_helpers.rb
index 2b1fa2f61..7061e75c1 100644
--- a/test/object_helpers.rb
+++ b/test/object_helpers.rb
@@ -105,6 +105,12 @@ module ObjectHelpers
issue.reload
end
+ def Issue.generate_with_child!(attributes={})
+ issue = Issue.generate!(attributes)
+ Issue.generate!(:parent_issue_id => issue.id)
+ issue.reload
+ end
+
def Journal.generate!(attributes={})
journal = Journal.new(attributes)
journal.user ||= User.first
diff --git a/test/unit/issue_nested_set_test.rb b/test/unit/issue_nested_set_test.rb
index 6fb5b0045..632464872 100644
--- a/test/unit/issue_nested_set_test.rb
+++ b/test/unit/issue_nested_set_test.rb
@@ -287,35 +287,6 @@ class IssueNestedSetTest < ActiveSupport::TestCase
end
end
- def test_parent_priority_should_be_the_highest_child_priority
- parent = Issue.generate!(:priority => IssuePriority.find_by_name('Normal'))
- # Create children
- child1 = parent.generate_child!(:priority => IssuePriority.find_by_name('High'))
- assert_equal 'High', parent.reload.priority.name
- child2 = child1.generate_child!(:priority => IssuePriority.find_by_name('Immediate'))
- assert_equal 'Immediate', child1.reload.priority.name
- assert_equal 'Immediate', parent.reload.priority.name
- child3 = parent.generate_child!(:priority => IssuePriority.find_by_name('Low'))
- assert_equal 'Immediate', parent.reload.priority.name
- # Destroy a child
- child1.destroy
- assert_equal 'Low', parent.reload.priority.name
- # Update a child
- child3.reload.priority = IssuePriority.find_by_name('Normal')
- child3.save!
- assert_equal 'Normal', parent.reload.priority.name
- end
-
- def test_parent_dates_should_be_lowest_start_and_highest_due_dates
- parent = Issue.generate!
- parent.generate_child!(:start_date => '2010-01-25', :due_date => '2010-02-15')
- parent.generate_child!( :due_date => '2010-02-13')
- parent.generate_child!(:start_date => '2010-02-01', :due_date => '2010-02-22')
- parent.reload
- assert_equal Date.parse('2010-01-25'), parent.start_date
- assert_equal Date.parse('2010-02-22'), parent.due_date
- end
-
def test_parent_done_ratio_should_be_average_done_ratio_of_leaves
parent = Issue.generate!
parent.generate_child!(:done_ratio => 20)
@@ -390,20 +361,6 @@ class IssueNestedSetTest < ActiveSupport::TestCase
assert_nil first_parent.reload.estimated_hours
end
- def test_reschuling_a_parent_should_reschedule_subtasks
- parent = Issue.generate!
- c1 = parent.generate_child!(:start_date => '2010-05-12', :due_date => '2010-05-18')
- c2 = parent.generate_child!(:start_date => '2010-06-03', :due_date => '2010-06-10')
- parent.reload
- 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
- assert_equal [Date.parse('2010-06-03'), Date.parse('2010-06-10')], [c2.start_date, c2.due_date] # no change
- parent.reload
- assert_equal [Date.parse('2010-06-02'), Date.parse('2010-06-10')], [parent.start_date, parent.due_date]
- end
-
def test_project_copy_should_copy_issue_tree
p = Project.create!(:name => 'Tree copy', :identifier => 'tree-copy', :tracker_ids => [1, 2])
i1 = Issue.generate!(:project => p, :subject => 'i1')
diff --git a/test/unit/issue_subtasking_test.rb b/test/unit/issue_subtasking_test.rb
new file mode 100644
index 000000000..621af178a
--- /dev/null
+++ b/test/unit/issue_subtasking_test.rb
@@ -0,0 +1,146 @@
+# Redmine - project management software
+# Copyright (C) 2006-2015 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 IssueSubtaskingTest < ActiveSupport::TestCase
+ fixtures :projects, :users, :roles, :members, :member_roles,
+ :trackers, :projects_trackers,
+ :issue_statuses, :issue_categories, :enumerations,
+ :issues
+
+ def test_leaf_planning_fields_should_be_editable
+ issue = Issue.generate!
+ user = User.find(1)
+ %w(priority_id done_ratio start_date due_date estimated_hours).each do |attribute|
+ assert issue.safe_attribute?(attribute, user)
+ end
+ end
+
+ def test_parent_dates_should_be_read_only_with_parent_issue_dates_set_to_derived
+ with_settings :parent_issue_dates => 'derived' do
+ issue = Issue.generate_with_child!
+ user = User.find(1)
+ %w(start_date due_date).each do |attribute|
+ assert !issue.safe_attribute?(attribute, user)
+ end
+ end
+ end
+
+ def test_parent_dates_should_be_lowest_start_and_highest_due_dates_with_parent_issue_dates_set_to_derived
+ with_settings :parent_issue_dates => 'derived' do
+ parent = Issue.generate!
+ parent.generate_child!(:start_date => '2010-01-25', :due_date => '2010-02-15')
+ parent.generate_child!( :due_date => '2010-02-13')
+ parent.generate_child!(:start_date => '2010-02-01', :due_date => '2010-02-22')
+ parent.reload
+ assert_equal Date.parse('2010-01-25'), parent.start_date
+ assert_equal Date.parse('2010-02-22'), parent.due_date
+ end
+ end
+
+ def test_reschuling_a_parent_should_reschedule_subtasks_with_parent_issue_dates_set_to_derived
+ with_settings :parent_issue_dates => 'derived' do
+ parent = Issue.generate!
+ c1 = parent.generate_child!(:start_date => '2010-05-12', :due_date => '2010-05-18')
+ c2 = parent.generate_child!(:start_date => '2010-06-03', :due_date => '2010-06-10')
+ parent.reload.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
+ assert_equal [Date.parse('2010-06-03'), Date.parse('2010-06-10')], [c2.start_date, c2.due_date] # no change
+ parent.reload
+ assert_equal [Date.parse('2010-06-02'), Date.parse('2010-06-10')], [parent.start_date, parent.due_date]
+ end
+ end
+
+ def test_parent_priority_should_be_read_only_with_parent_issue_priority_set_to_derived
+ with_settings :parent_issue_priority => 'derived' do
+ issue = Issue.generate_with_child!
+ user = User.find(1)
+ assert !issue.safe_attribute?('priority_id', user)
+ end
+ end
+
+ def test_parent_priority_should_be_the_highest_child_priority
+ with_settings :parent_issue_priority => 'derived' do
+ parent = Issue.generate!(:priority => IssuePriority.find_by_name('Normal'))
+ # Create children
+ child1 = parent.generate_child!(:priority => IssuePriority.find_by_name('High'))
+ assert_equal 'High', parent.reload.priority.name
+ child2 = child1.generate_child!(:priority => IssuePriority.find_by_name('Immediate'))
+ assert_equal 'Immediate', child1.reload.priority.name
+ assert_equal 'Immediate', parent.reload.priority.name
+ child3 = parent.generate_child!(:priority => IssuePriority.find_by_name('Low'))
+ assert_equal 'Immediate', parent.reload.priority.name
+ # Destroy a child
+ child1.destroy
+ assert_equal 'Low', parent.reload.priority.name
+ # Update a child
+ child3.reload.priority = IssuePriority.find_by_name('Normal')
+ child3.save!
+ assert_equal 'Normal', parent.reload.priority.name
+ end
+ end
+
+ def test_parent_dates_should_be_editable_with_parent_issue_dates_set_to_independent
+ with_settings :parent_issue_dates => 'independent' do
+ issue = Issue.generate_with_child!
+ user = User.find(1)
+ %w(start_date due_date).each do |attribute|
+ assert issue.safe_attribute?(attribute, user)
+ end
+ end
+ end
+
+ def test_parent_dates_should_not_be_updated_with_parent_issue_dates_set_to_independent
+ with_settings :parent_issue_dates => 'independent' do
+ parent = Issue.generate!(:start_date => '2015-07-01', :due_date => '2015-08-01')
+ parent.generate_child!(:start_date => '2015-06-01', :due_date => '2015-09-01')
+ parent.reload
+ assert_equal Date.parse('2015-07-01'), parent.start_date
+ assert_equal Date.parse('2015-08-01'), parent.due_date
+ end
+ end
+
+ def test_reschuling_a_parent_should_not_reschedule_subtasks_with_parent_issue_dates_set_to_independent
+ with_settings :parent_issue_dates => 'independent' do
+ parent = Issue.generate!(:start_date => '2010-05-01', :due_date => '2010-05-20')
+ c1 = parent.generate_child!(:start_date => '2010-05-12', :due_date => '2010-05-18')
+ parent.reload.reschedule_on!(Date.parse('2010-06-01'))
+ assert_equal Date.parse('2010-06-01'), parent.reload.start_date
+ c1.reload
+ assert_equal [Date.parse('2010-05-12'), Date.parse('2010-05-18')], [c1.start_date, c1.due_date]
+ end
+ end
+
+ def test_parent_priority_should_be_editable_with_parent_issue_priority_set_to_independent
+ with_settings :parent_issue_priority => 'independent' do
+ issue = Issue.generate_with_child!
+ user = User.find(1)
+ assert issue.safe_attribute?('priority_id', user)
+ end
+ end
+
+ def test_parent_priority_should_not_be_updated_with_parent_issue_priority_set_to_independent
+ with_settings :parent_issue_priority => 'independent' do
+ parent = Issue.generate!(:priority => IssuePriority.find_by_name('Normal'))
+ child1 = parent.generate_child!(:priority => IssuePriority.find_by_name('High'))
+ assert_equal 'Normal', parent.reload.priority.name
+ end
+ end
+end