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}
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")