From 6a37151b5cd0086b53b6c9fd336ff143c4defd42 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 8 Sep 2012 05:56:48 +0000 Subject: [PATCH] Adapt subtasks copy when copying a project (#6965). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10328 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/project.rb | 2 +- test/unit/project_test.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index 92af86f12..4c4d0f9f1 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -773,7 +773,7 @@ class Project < ActiveRecord::Base # get copied before their children project.issues.find(:all, :order => 'root_id, lft').each do |issue| new_issue = Issue.new - new_issue.copy_from(issue) + new_issue.copy_from(issue, :subtasks => false) new_issue.project = self # Reassign fixed_versions by name, since names are unique per # project and the versions for self are not yet saved diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb index 3abfbe327..1171c5e93 100644 --- a/test/unit/project_test.rb +++ b/test/unit/project_test.rb @@ -1018,7 +1018,23 @@ class ProjectTest < ActiveSupport::TestCase assert @project.issue_categories.any? assert @project.issues.empty? end + end + def test_copy_should_copy_subtasks + source = Project.generate!(:tracker_ids => [1]) + issue = Issue.generate_with_descendants!(source, :subject => 'Parent') + project = Project.new(:name => 'Copy', :identifier => 'copy', :tracker_ids => [1]) + + assert_difference 'Project.count' do + assert_difference 'Issue.count', 1+issue.descendants.count do + assert project.copy(source.reload) + end + end + copy = Issue.where(:parent_id => nil).order("id DESC").first + assert_equal project, copy.project + assert_equal issue.descendants.count, copy.descendants.count + child_copy = copy.children.detect {|c| c.subject == 'Child1'} + assert child_copy.descendants.any? end context "#start_date" do