@@ -899,6 +899,22 class Project < ActiveRecord::Base | |||||
899 | if issue.fixed_version && issue.fixed_version.project == project |
|
899 | if issue.fixed_version && issue.fixed_version.project == project | |
900 | new_issue.fixed_version = self.versions.detect {|v| v.name == issue.fixed_version.name} |
|
900 | new_issue.fixed_version = self.versions.detect {|v| v.name == issue.fixed_version.name} | |
901 | end |
|
901 | end | |
|
902 | # Reassign version custom field values | |||
|
903 | new_issue.custom_field_values.each do |custom_value| | |||
|
904 | if custom_value.custom_field.field_format == 'version' && custom_value.value.present? | |||
|
905 | versions = Version.where(:id => custom_value.value).to_a | |||
|
906 | new_value = versions.map do |version| | |||
|
907 | if version.project == project | |||
|
908 | self.versions.detect {|v| v.name == version.name}.try(:id) | |||
|
909 | else | |||
|
910 | version.id | |||
|
911 | end | |||
|
912 | end | |||
|
913 | new_value.compact! | |||
|
914 | new_value = new_value.first unless custom_value.custom_field.multiple? | |||
|
915 | custom_value.value = new_value | |||
|
916 | end | |||
|
917 | end | |||
902 | # Reassign the category by name, since names are unique per project |
|
918 | # Reassign the category by name, since names are unique per project | |
903 | if issue.category |
|
919 | if issue.category | |
904 | new_issue.category = self.issue_categories.detect {|c| c.name == issue.category.name} |
|
920 | new_issue.category = self.issue_categories.detect {|c| c.name == issue.category.name} |
@@ -139,6 +139,27 class ProjectCopyTest < ActiveSupport::TestCase | |||||
139 | assert_equal assigned_version, copied_issue.fixed_version |
|
139 | assert_equal assigned_version, copied_issue.fixed_version | |
140 | end |
|
140 | end | |
141 |
|
141 | |||
|
142 | def test_copy_issues_should_reassign_version_custom_fields_to_copied_versions | |||
|
143 | User.current = User.find(1) | |||
|
144 | CustomField.delete_all | |||
|
145 | field = IssueCustomField.generate!(:field_format => 'version', :is_for_all => true, :trackers => Tracker.all) | |||
|
146 | source_project = Project.generate!(:trackers => Tracker.all) | |||
|
147 | source_version = Version.generate!(:project => source_project) | |||
|
148 | source_issue = Issue.generate!(:project => source_project) do |issue| | |||
|
149 | issue.custom_field_values = {field.id.to_s => source_version.id.to_s} | |||
|
150 | end | |||
|
151 | assert_equal source_version.id.to_s, source_issue.custom_field_value(field) | |||
|
152 | ||||
|
153 | project = Project.new(:name => 'Copy Test', :identifier => 'copy-test', :trackers => Tracker.all) | |||
|
154 | assert project.copy(source_project) | |||
|
155 | assert_equal 1, project.issues.count | |||
|
156 | issue = project.issues.first | |||
|
157 | assert_equal 1, project.versions.count | |||
|
158 | version = project.versions.first | |||
|
159 | ||||
|
160 | assert_equal version.id.to_s, issue.custom_field_value(field) | |||
|
161 | end | |||
|
162 | ||||
142 | test "#copy should copy issue relations" do |
|
163 | test "#copy should copy issue relations" do | |
143 | Setting.cross_project_issue_relations = '1' |
|
164 | Setting.cross_project_issue_relations = '1' | |
144 |
|
165 |
General Comments 0
You need to be logged in to leave comments.
Login now