From 5003927f13f54850ca9eeac48e353df5e4e325a1 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 8 Sep 2012 05:34:07 +0000 Subject: Option to copy subtasks when copying issue(s) (#6965). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10327 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- test/unit/issue_test.rb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'test/unit') diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index a3df951a6..59f38dbd8 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -633,6 +633,41 @@ class IssueTest < ActiveSupport::TestCase assert_equal orig.status, issue.status end + def test_copy_should_copy_subtasks + issue = Issue.generate_with_descendants!(Project.find(1), :subject => 'Parent') + + copy = issue.reload.copy + copy.author = User.find(7) + assert_difference 'Issue.count', 1+issue.descendants.count do + assert copy.save + end + copy.reload + assert_equal %w(Child1 Child2), copy.children.map(&:subject).sort + child_copy = copy.children.detect {|c| c.subject == 'Child1'} + assert_equal %w(Child11), child_copy.children.map(&:subject).sort + assert_equal copy.author, child_copy.author + end + + def test_copy_should_copy_subtasks_to_target_project + issue = Issue.generate_with_descendants!(Project.find(1), :subject => 'Parent') + + copy = issue.copy(:project_id => 3) + assert_difference 'Issue.count', 1+issue.descendants.count do + assert copy.save + end + assert_equal [3], copy.reload.descendants.map(&:project_id).uniq + end + + def test_copy_should_not_copy_subtasks_twice_when_saving_twice + issue = Issue.generate_with_descendants!(Project.find(1), :subject => 'Parent') + + copy = issue.reload.copy + assert_difference 'Issue.count', 1+issue.descendants.count do + assert copy.save + assert copy.save + end + end + def test_should_not_call_after_project_change_on_creation issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1, :subject => 'Test', :author_id => 1) issue.expects(:after_project_change).never -- cgit v1.2.3