diff --git a/app/models/project.rb b/app/models/project.rb index c438be16d4..40c9a58306 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1120,6 +1120,11 @@ class Project < ApplicationRecord attachment.copy(:container => new_version) end + new_version.custom_field_values = version.custom_field_values.inject({}) do |h, v| + h[v.custom_field_id] = v.value + h + end + self.versions << new_version end end diff --git a/test/unit/project_copy_test.rb b/test/unit/project_copy_test.rb index 7f9376d3d3..326525df83 100644 --- a/test/unit/project_copy_test.rb +++ b/test/unit/project_copy_test.rb @@ -151,6 +151,19 @@ class ProjectCopyTest < ActiveSupport::TestCase assert_equal assigned_version, copied_issue.fixed_version end + test "#copy should copy versions custom values" do + field = VersionCustomField.generate!(:is_for_all => true) + version = Version.generate!(:project => @source_project, :name => 'Version for custom field copy') + version.custom_field_values = {field.id => 'version custom field value'} + version.save! + assert_equal 'version custom field value', version.reload.custom_field_value(field) + + assert @project.copy(@source_project) + copy = @project.versions.find_by_name('Version for custom field copy') + assert copy + assert_equal 'version custom field value', copy.reload.custom_field_value(field) + end + def test_copy_issues_should_reassign_version_custom_fields_to_copied_versions User.current = User.find(1) CustomField.destroy_all