]> source.dussan.org Git - redmine.git/commitdiff
Copy version attachments (i.e. Files) along with the versions on project copy (#26622).
authorGo MAEDA <maeda@farend.jp>
Sun, 13 May 2018 08:48:10 +0000 (08:48 +0000)
committerGo MAEDA <maeda@farend.jp>
Sun, 13 May 2018 08:48:10 +0000 (08:48 +0000)
Patch by Holger Just.

git-svn-id: http://svn.redmine.org/redmine/trunk@17332 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/project.rb
test/unit/project_copy_test.rb

index 1268f11cd7eedb3d8ad4184d8b9b596d95ece933..5d96236798c5672e2ca78d4406bc03bf105f5a46 100644 (file)
@@ -951,6 +951,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
index 56f485c7647324cbabd2b3bbc75749324d0ee73e..9352c0d04c2506e67c07fd508434fa8deb9e0458 100644 (file)
@@ -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)