Project copy does not update custom field of version type values (#20361).

git-svn-id: http://svn.redmine.org/redmine/trunk@14615 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2015-09-20 12:50:06 +00:00
parent eb57fa4847
commit a28bf20c4c
2 changed files with 37 additions and 0 deletions

View File

@@ -899,6 +899,22 @@ class Project < ActiveRecord::Base
if issue.fixed_version && issue.fixed_version.project == project
new_issue.fixed_version = self.versions.detect {|v| v.name == issue.fixed_version.name}
end
# Reassign version custom field values
new_issue.custom_field_values.each do |custom_value|
if custom_value.custom_field.field_format == 'version' && custom_value.value.present?
versions = Version.where(:id => custom_value.value).to_a
new_value = versions.map do |version|
if version.project == project
self.versions.detect {|v| v.name == version.name}.try(:id)
else
version.id
end
end
new_value.compact!
new_value = new_value.first unless custom_value.custom_field.multiple?
custom_value.value = new_value
end
end
# Reassign the category by name, since names are unique per project
if issue.category
new_issue.category = self.issue_categories.detect {|c| c.name == issue.category.name}

View File

@@ -139,6 +139,27 @@ class ProjectCopyTest < ActiveSupport::TestCase
assert_equal assigned_version, copied_issue.fixed_version
end
def test_copy_issues_should_reassign_version_custom_fields_to_copied_versions
User.current = User.find(1)
CustomField.delete_all
field = IssueCustomField.generate!(:field_format => 'version', :is_for_all => true, :trackers => Tracker.all)
source_project = Project.generate!(:trackers => Tracker.all)
source_version = Version.generate!(:project => source_project)
source_issue = Issue.generate!(:project => source_project) do |issue|
issue.custom_field_values = {field.id.to_s => source_version.id.to_s}
end
assert_equal source_version.id.to_s, source_issue.custom_field_value(field)
project = Project.new(:name => 'Copy Test', :identifier => 'copy-test', :trackers => Tracker.all)
assert project.copy(source_project)
assert_equal 1, project.issues.count
issue = project.issues.first
assert_equal 1, project.versions.count
version = project.versions.first
assert_equal version.id.to_s, issue.custom_field_value(field)
end
test "#copy should copy issue relations" do
Setting.cross_project_issue_relations = '1'