]> source.dussan.org Git - redmine.git/commitdiff
Copy project attachments (#26622).
authorGo MAEDA <maeda@farend.jp>
Sun, 13 May 2018 08:49:18 +0000 (08:49 +0000)
committerGo MAEDA <maeda@farend.jp>
Sun, 13 May 2018 08:49:18 +0000 (08:49 +0000)
Patch by Holger Just.

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

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

index 5d96236798c5672e2ca78d4406bc03bf105f5a46..5f2f2fb102245090d0eb04fafdfc6e90369f595a 100644 (file)
@@ -827,6 +827,11 @@ class Project < ActiveRecord::Base
     Project.transaction do
       if save
         reload
+
+        self.attachments = project.attachments.map do |attachment|
+          attachment.copy(:container => self)
+        end
+
         to_be_copied.each do |name|
           send "copy_#{name}", project
         end
index 9352c0d04c2506e67c07fd508434fa8deb9e0458..05d5d2e4d3716bbb65ff35027ee734de94f6760d 100644 (file)
@@ -51,6 +51,14 @@ class ProjectCopyTest < ActiveSupport::TestCase
     assert_equal false, project.copy(@source_project)
   end
 
+  test "#copy should copy project attachments" do
+    Attachment.create!(:container => @source_project, :file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 1)
+    assert @project.copy(@source_project)
+
+    assert_equal 1, @project.attachments.count, "Attachment not copied"
+    assert_equal "testfile.txt", @project.attachments.first.filename
+  end
+
   test "#copy should copy issues" do
     @source_project.issues << Issue.generate!(:status => IssueStatus.find_by_name('Closed'),
                                               :subject => "copy issue status",