diff --git a/app/models/project.rb b/app/models/project.rb index da58c96db..5503cbb76 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -763,12 +763,17 @@ class Project < ActiveRecord::Base end # Copies issues from +project+ - # Note: issues assigned to a closed version won't be copied due to validation rules def copy_issues(project) # Stores the source issue id as a key and the copied issues as the # value. Used to map the two togeather for issue relations. issues_map = {} + # Store status and reopen locked/closed versions + version_statuses = versions.reject(&:open?).map {|version| [version, version.status]} + version_statuses.each do |version, status| + version.update_attribute :status, 'open' + end + # Get issues sorted by root_id, lft so that parent issues # get copied before their children project.issues.find(:all, :order => 'root_id, lft').each do |issue| @@ -798,6 +803,11 @@ class Project < ActiveRecord::Base end end + # Restore locked/closed version statuses + version_statuses.each do |version, status| + version.update_attribute :status, status + end + # Relations after in case issues related each other project.issues.each do |issue| new_issue = issues_map[issue.id] diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb index fac2307ed..7910707b2 100644 --- a/test/unit/project_test.rb +++ b/test/unit/project_test.rb @@ -823,6 +823,27 @@ class ProjectTest < ActiveSupport::TestCase assert_equal "Closed", copied_issue.status.name end + should "copy issues assigned to a locked version" do + User.current = User.find(1) + assigned_version = Version.generate!(:name => "Assigned Issues") + @source_project.versions << assigned_version + Issue.generate_for_project!(@source_project, + :fixed_version_id => assigned_version.id, + :subject => "copy issues assigned to a locked version", + :tracker_id => 1, + :project_id => @source_project.id) + assigned_version.update_attribute :status, 'locked' + + assert @project.copy(@source_project) + @project.reload + copied_issue = @project.issues.first(:conditions => {:subject => "copy issues assigned to a locked version"}) + + assert copied_issue + assert copied_issue.fixed_version + assert_equal "Assigned Issues", copied_issue.fixed_version.name # Same name + assert_equal 'locked', copied_issue.fixed_version.status + end + should "change the new issues to use the copied version" do User.current = User.find(1) assigned_version = Version.generate!(:name => "Assigned Issues", :status => 'open')