From 8376ffc239eb0217c01b010b016108423a8c13b1 Mon Sep 17 00:00:00 2001 From: Holger Just Date: Thu, 3 Aug 2017 19:05:50 +0200 Subject: [PATCH] Copy version attachments (i.e. Files) along with the versions on project copy --- app/models/project.rb | 5 +++++ test/unit/project_copy_test.rb | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/app/models/project.rb b/app/models/project.rb index 06660adc4..98b186d9d 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -950,6 +950,11 @@ class Project < ActiveRecord::Base project.versions.each do |version| new_version = Version.new new_version.attributes = version.attributes.dup.except("id", "project_id", "created_on", "updated_on") + + new_version.attachments = version.attachments.map do |attachment| + attachment.copy(:container => new_version) + end + self.versions << new_version end end diff --git a/test/unit/project_copy_test.rb b/test/unit/project_copy_test.rb index a1292204b..71f5b5002 100644 --- a/test/unit/project_copy_test.rb +++ b/test/unit/project_copy_test.rb @@ -284,6 +284,18 @@ class ProjectCopyTest < ActiveSupport::TestCase end end + test "#copy should copy version attachments" do + version = Version.generate!(:name => "copy with attachment") + Attachment.create!(:container => version, :file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 1) + @source_project.versions << version + assert @project.copy(@source_project) + + copied_version = @project.versions.where(:name => "copy with attachment").first + assert_not_nil copied_version + assert_equal 1, copied_version.attachments.count, "Attachment not copied" + assert_equal "testfile.txt", copied_version.attachments.first.filename + end + test "#copy should copy wiki" do assert_difference 'Wiki.count' do assert @project.copy(@source_project) -- 2.13.0