Commit 2ed8f6b6 authored by maeda's avatar maeda

Allows re-use of thumbnails for identical attachments (#30177).

Patch by Jens Krämer.


git-svn-id: https://svn.redmine.org/redmine/trunk@17735 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent fcef29ac
......@@ -216,7 +216,7 @@ class Attachment < ActiveRecord::Base
size = Setting.thumbnails_size.to_i
end
size = 100 unless size > 0
target = File.join(self.class.thumbnails_storage_path, "#{id}_#{digest}_#{size}.thumb")
target = File.join(self.class.thumbnails_storage_path, "#{digest}_#{filesize}_#{size}.thumb")
begin
Redmine::Thumbnail.generate(self.diskfile, target, size)
......
......@@ -430,11 +430,33 @@ class AttachmentTest < ActiveSupport::TestCase
assert_difference "Dir.glob(File.join(Attachment.thumbnails_storage_path, '*.thumb')).size" do
thumbnail = attachment.thumbnail
assert_equal "16_8e0294de2441577c529f170b6fb8f638_100.thumb", File.basename(thumbnail)
assert_equal "8e0294de2441577c529f170b6fb8f638_2654_100.thumb", File.basename(thumbnail)
assert File.exists?(thumbnail)
end
end
def test_should_reuse_thumbnail
a = Attachment.create!(
:container => Issue.find(1),
:file => uploaded_test_file("2010/11/101123161450_testfile_1.png", "image/png"),
:author => User.find(1)
)
a_thumb = b_thumb = nil
assert_difference "Dir.glob(File.join(Attachment.thumbnails_storage_path, '*.thumb')).size" do
a_thumb = a.thumbnail
end
b = Attachment.create!(
:container => Issue.find(2),
:file => uploaded_test_file("2010/11/101123161450_testfile_1.png", "image/png"),
:author => User.find(1)
)
assert_no_difference "Dir.glob(File.join(Attachment.thumbnails_storage_path, '*.thumb')).size" do
b_thumb = b.thumbnail
end
assert_equal a_thumb, b_thumb
end
def test_thumbnail_should_return_nil_if_generation_fails
Redmine::Thumbnail.expects(:generate).raises(SystemCallError, 'Something went wrong')
set_fixtures_attachments_directory
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment