]> source.dussan.org Git - redmine.git/commitdiff
Merged r20094 from trunk to 4.1-stable (#33769).
authorGo MAEDA <maeda@farend.jp>
Wed, 30 Sep 2020 13:46:46 +0000 (13:46 +0000)
committerGo MAEDA <maeda@farend.jp>
Wed, 30 Sep 2020 13:46:46 +0000 (13:46 +0000)
git-svn-id: http://svn.redmine.org/redmine/branches/4.1-stable@20095 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/attachment.rb
test/unit/attachment_test.rb

index 627c1a1811d2e5d7363fc01eaff29cc83c10a95b..cf0ef576507a2287d68e6d446e149eeac2f979bd 100644 (file)
@@ -442,7 +442,8 @@ class Attachment < ActiveRecord::Base
                       .where(digest: self.digest, filesize: self.filesize)
                       .where('id <> ? and disk_filename <> ?',
                              self.id, self.disk_filename)
-                      .first
+                      .order(:id)
+                      .last
         existing.with_lock do
           original_diskfile = self.diskfile
           existing_diskfile = existing.diskfile
index 83127863453abad788e8c68fe4c0d633aaa3d1b1..e2b6bb85ed4e932ba3f55117f4b9c4961132f108 100644 (file)
@@ -235,6 +235,23 @@ class AttachmentTest < ActiveSupport::TestCase
     assert_not_equal a1.diskfile, a2.diskfile
   end
 
+  def test_identical_attachments_created_in_same_transaction_should_not_end_up_unreadable
+    attachments = []
+    Project.transaction do
+      3.times do
+        a = Attachment.create!(
+          :container => Issue.find(1), :author => User.find(1),
+          :file => mock_file(:filename => 'foo', :content => 'abcde')
+        )
+        attachments << a
+      end
+    end
+    attachments.each do |a|
+      assert a.readable?
+    end
+    assert_equal 1, attachments.map(&:diskfile).uniq.size
+  end
+
   def test_filename_should_be_basenamed
     a = Attachment.new(:file => mock_file(:original_filename => "path/to/the/file"))
     assert_equal 'file', a.filename