Fixed: Issues associated with a locked version are not copied when copying a project (#11207).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10334 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-09-09 10:11:49 +00:00
parent 5e9320137b
commit ff86c37ed3
2 changed files with 32 additions and 1 deletions

View File

@ -763,12 +763,17 @@ class Project < ActiveRecord::Base
end end
# Copies issues from +project+ # Copies issues from +project+
# Note: issues assigned to a closed version won't be copied due to validation rules
def copy_issues(project) def copy_issues(project)
# Stores the source issue id as a key and the copied issues as the # Stores the source issue id as a key and the copied issues as the
# value. Used to map the two togeather for issue relations. # value. Used to map the two togeather for issue relations.
issues_map = {} 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 issues sorted by root_id, lft so that parent issues
# get copied before their children # get copied before their children
project.issues.find(:all, :order => 'root_id, lft').each do |issue| project.issues.find(:all, :order => 'root_id, lft').each do |issue|
@ -798,6 +803,11 @@ class Project < ActiveRecord::Base
end end
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 # Relations after in case issues related each other
project.issues.each do |issue| project.issues.each do |issue|
new_issue = issues_map[issue.id] new_issue = issues_map[issue.id]

View File

@ -823,6 +823,27 @@ class ProjectTest < ActiveSupport::TestCase
assert_equal "Closed", copied_issue.status.name assert_equal "Closed", copied_issue.status.name
end 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 should "change the new issues to use the copied version" do
User.current = User.find(1) User.current = User.find(1)
assigned_version = Version.generate!(:name => "Assigned Issues", :status => 'open') assigned_version = Version.generate!(:name => "Assigned Issues", :status => 'open')