Commit 6036202293cfc36a5ed11bc07f773ca12f53f0cf
1 parent
8030dfa9
Exists in
master
and in
28 other branches
Avoid creating background jobs for thumbnails also
(ActionItem1661)
Showing
2 changed files
with
11 additions
and
1 deletions
Show diff stats
lib/delayed_attachment_fu.rb
@@ -4,7 +4,7 @@ module DelayedAttachmentFu | @@ -4,7 +4,7 @@ module DelayedAttachmentFu | ||
4 | def delay_attachment_fu_thumbnails | 4 | def delay_attachment_fu_thumbnails |
5 | include DelayedAttachmentFu::InstanceMethods | 5 | include DelayedAttachmentFu::InstanceMethods |
6 | after_create do |file| | 6 | after_create do |file| |
7 | - if file.image? | 7 | + if file.thumbnailable? |
8 | Delayed::Job.enqueue CreateThumbnailsJob.new(file.class.name, file.id) | 8 | Delayed::Job.enqueue CreateThumbnailsJob.new(file.class.name, file.id) |
9 | end | 9 | end |
10 | end | 10 | end |
test/unit/image_test.rb
@@ -84,4 +84,14 @@ class ImageTest < Test::Unit::TestCase | @@ -84,4 +84,14 @@ class ImageTest < Test::Unit::TestCase | ||
84 | end | 84 | end |
85 | end | 85 | end |
86 | 86 | ||
87 | + should 'not create a background job for an image that is already a thumbnail' do | ||
88 | + # this test verifies whether it created background jobs also for the | ||
89 | + # thumbnails! | ||
90 | + assert_no_difference Delayed::Job, :count do | ||
91 | + image = Image.new(:owner => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | ||
92 | + image.stubs(:is_thumbnail?).returns(true) | ||
93 | + image.save! | ||
94 | + end | ||
95 | + end | ||
96 | + | ||
87 | end | 97 | end |