Clean pull request with tests for mphallidays original bugfix. #51

Merged
merged 1 commit into from Nov 23, 2011
View
9 lib/delayed_paperclip/attachment.rb
@@ -45,7 +45,14 @@ def process_delayed!
def post_process_styles_with_processing(*args)
post_process_styles_without_processing(*args)
- instance.update_attribute("#{name}_processing", false) if instance.respond_to?(:"#{name}_processing?")
+
+ # update_column is available in rails 3.1 instead we can do this to update the attribute without callbacks
+
+ #instance.update_column("#{name}_processing", false) if instance.respond_to?(:"#{name}_processing?")
+ if instance.respond_to?(:"#{name}_processing?")
+ instance.send("#{name}_processing=", false)
+ instance.class.update_all({ "#{name}_processing" => false }, instance.class.primary_key => instance.id)
+ end
end
def save_with_prepare_enqueueing
View
10 test/base_delayed_paperclip_test.rb
@@ -137,4 +137,14 @@ def test_after_callback_is_functional
dummy.save!
process_jobs
end
+
+ def test_delayed_paperclip_functioning_with_after_update_callback
+ reset_class "Dummy", :with_processed => true, :with_after_update_callback => true
+ Dummy.any_instance.expects(:reprocess)
+ dummy = Dummy.new(:image => File.open("#{RAILS_ROOT}/test/fixtures/12k.png"))
+ dummy.save!
+ process_jobs
+ dummy.update_attributes(:name => "hi")
+ end
+
end
View
6 test/test_helper.rb
@@ -41,6 +41,7 @@ def reset_dummy(options = {})
def build_dummy_table(with_processed)
ActiveRecord::Base.connection.create_table :dummies, :force => true do |t|
+ t.string :name
t.string :image_file_name
t.string :image_content_type
t.integer :image_file_size
@@ -57,6 +58,11 @@ def reset_class(class_name, options)
include Paperclip::Glue
has_attached_file :image
process_in_background :image, options if options[:with_processed]
+ after_update :reprocess if options[:with_after_update_callback]
+
+ def reprocess
+ image.reprocess!
+ end
end
klass.reset_column_information
klass