summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2020-09-30 13:57:52 +0000
committerGo MAEDA <maeda@farend.jp>2020-09-30 13:57:52 +0000
commitdd73415d5349f2c7ad22ea0a90a9470bd6fa0ea0 (patch)
tree4afdabdd44870428a2b9d271955b66f66b5b6295
parent656c0db0cc3074804726c0f9a0258d7a81d64696 (diff)
downloadredmine-dd73415d5349f2c7ad22ea0a90a9470bd6fa0ea0.tar.gz
redmine-dd73415d5349f2c7ad22ea0a90a9470bd6fa0ea0.zip
Merged r20094 from trunk to 4.0-stable (#33769).
git-svn-id: http://svn.redmine.org/redmine/branches/4.0-stable@20096 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/models/attachment.rb3
-rw-r--r--test/unit/attachment_test.rb17
2 files changed, 19 insertions, 1 deletions
diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index 3affca0ba..1f19f810a 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -431,7 +431,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
diff --git a/test/unit/attachment_test.rb b/test/unit/attachment_test.rb
index 4e90ee03e..144fb5425 100644
--- a/test/unit/attachment_test.rb
+++ b/test/unit/attachment_test.rb
@@ -234,6 +234,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