From 6036202293cfc36a5ed11bc07f773ca12f53f0cf Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Thu, 2 Sep 2010 16:52:02 -0300 Subject: [PATCH] Avoid creating background jobs for thumbnails also --- lib/delayed_attachment_fu.rb | 2 +- test/unit/image_test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/delayed_attachment_fu.rb b/lib/delayed_attachment_fu.rb index 5193245..87ffbf8 100644 --- a/lib/delayed_attachment_fu.rb +++ b/lib/delayed_attachment_fu.rb @@ -4,7 +4,7 @@ module DelayedAttachmentFu def delay_attachment_fu_thumbnails include DelayedAttachmentFu::InstanceMethods after_create do |file| - if file.image? + if file.thumbnailable? Delayed::Job.enqueue CreateThumbnailsJob.new(file.class.name, file.id) end end diff --git a/test/unit/image_test.rb b/test/unit/image_test.rb index b29a651..8357b30 100644 --- a/test/unit/image_test.rb +++ b/test/unit/image_test.rb @@ -84,4 +84,14 @@ class ImageTest < Test::Unit::TestCase end end + should 'not create a background job for an image that is already a thumbnail' do + # this test verifies whether it created background jobs also for the + # thumbnails! + assert_no_difference Delayed::Job, :count do + image = Image.new(:owner => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) + image.stubs(:is_thumbnail?).returns(true) + image.save! + end + end + end -- libgit2 0.21.2