From: Jean-Philippe Lang Date: Mon, 13 May 2013 19:52:37 +0000 (+0000) Subject: Fixed that values of custom fields are not kept in issues when copying a project... X-Git-Tag: 2.4.0~360 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ece5232110d0ac148f45b9bac1badf1547ef6c87;p=redmine.git Fixed that values of custom fields are not kept in issues when copying a project (#13910). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11843 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/project.rb b/app/models/project.rb index 127362ff1..915644c6b 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -848,6 +848,9 @@ class Project < ActiveRecord::Base new_issue = Issue.new new_issue.copy_from(issue, :subtasks => false, :link => false) new_issue.project = self + # Changing project resets the custom field values + # TODO: handle this in Issue#project= + new_issue.custom_field_values = issue.custom_field_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h} # Reassign fixed_versions by name, since names are unique per project if issue.fixed_version && issue.fixed_version.project == project new_issue.fixed_version = self.versions.detect {|v| v.name == issue.fixed_version.name} diff --git a/test/unit/project_copy_test.rb b/test/unit/project_copy_test.rb index 6b505b2b2..893e6653f 100644 --- a/test/unit/project_copy_test.rb +++ b/test/unit/project_copy_test.rb @@ -69,6 +69,19 @@ class ProjectCopyTest < ActiveSupport::TestCase assert_equal "Closed", copied_issue.status.name end + test "#copy should copy issues custom values" do + field = IssueCustomField.generate!(:is_for_all => true, :trackers => Tracker.all) + issue = Issue.generate!(:project => @source_project, :subject => 'Custom field copy') + issue.custom_field_values = {field.id => 'custom'} + issue.save! + assert_equal 'custom', issue.reload.custom_field_value(field) + + assert @project.copy(@source_project) + copy = @project.issues.find_by_subject('Custom field copy') + assert copy + assert_equal 'custom', copy.reload.custom_field_value(field) + end + test "#copy should copy issues assigned to a locked version" do User.current = User.find(1) assigned_version = Version.generate!(:name => "Assigned Issues")