Patch #30177 » 0001-allows-re-use-of-thumbnails-for-identical-attachment.patch
app/models/attachment.rb | ||
---|---|---|
216 | 216 |
size = Setting.thumbnails_size.to_i |
217 | 217 |
end |
218 | 218 |
size = 100 unless size > 0 |
219 |
target = File.join(self.class.thumbnails_storage_path, "#{id}_#{digest}_#{size}.thumb")
|
|
219 |
target = File.join(self.class.thumbnails_storage_path, "#{digest}_#{filesize}_#{size}.thumb")
|
|
220 | 220 | |
221 | 221 |
begin |
222 | 222 |
Redmine::Thumbnail.generate(self.diskfile, target, size) |
test/unit/attachment_test.rb | ||
---|---|---|
429 | 429 | |
430 | 430 |
assert_difference "Dir.glob(File.join(Attachment.thumbnails_storage_path, '*.thumb')).size" do |
431 | 431 |
thumbnail = attachment.thumbnail |
432 |
assert_equal "16_8e0294de2441577c529f170b6fb8f638_100.thumb", File.basename(thumbnail)
|
|
432 |
assert_equal "8e0294de2441577c529f170b6fb8f638_2654_100.thumb", File.basename(thumbnail)
|
|
433 | 433 |
assert File.exists?(thumbnail) |
434 | 434 |
end |
435 | 435 |
end |
436 | 436 | |
437 |
def test_should_reuse_thumbnail |
|
438 |
a = Attachment.create!( |
|
439 |
:container => Issue.find(1), |
|
440 |
:file => uploaded_test_file("2010/11/101123161450_testfile_1.png", "image/png"), |
|
441 |
:author => User.find(1) |
|
442 |
) |
|
443 |
a_thumb = b_thumb = nil |
|
444 |
assert_difference "Dir.glob(File.join(Attachment.thumbnails_storage_path, '*.thumb')).size" do |
|
445 |
a_thumb = a.thumbnail |
|
446 |
end |
|
447 | ||
448 |
b = Attachment.create!( |
|
449 |
:container => Issue.find(2), |
|
450 |
:file => uploaded_test_file("2010/11/101123161450_testfile_1.png", "image/png"), |
|
451 |
:author => User.find(1) |
|
452 |
) |
|
453 |
assert_no_difference "Dir.glob(File.join(Attachment.thumbnails_storage_path, '*.thumb')).size" do |
|
454 |
b_thumb = b.thumbnail |
|
455 |
end |
|
456 |
assert_equal a_thumb, b_thumb |
|
457 |
end |
|
458 | ||
437 | 459 |
def test_thumbnail_should_return_nil_if_generation_fails |
438 | 460 |
Redmine::Thumbnail.expects(:generate).raises(SystemCallError, 'Something went wrong') |
439 | 461 |
set_fixtures_attachments_directory |