Commit e705b737 by Jon Yurek

Don't delete all the existing styles if we reprocess

parent a596c01b
......@@ -90,7 +90,7 @@ module Paperclip
ensure_required_accessors!
file = Paperclip.io_adapters.for(uploaded_file)
self.clear
self.clear(*@options[:only_process])
return nil if file.nil?
@queued_for_write[:original] = file
......@@ -202,10 +202,14 @@ module Paperclip
# Clears out the attachment. Has the same effect as previously assigning
# nil to the attachment. Does NOT save. If you wish to clear AND save,
# use #destroy.
def clear
queue_existing_for_delete
@queued_for_write = {}
@errors = {}
def clear(*styles_to_clear)
if styles_to_clear.any?
queue_some_for_delete(*styles_to_clear)
else
queue_all_for_delete
@queued_for_write = {}
@errors = {}
end
end
# Destroys the attachment. Has the same effect as previously assigning
......@@ -406,7 +410,13 @@ module Paperclip
interpolator.interpolate(pattern, self, style_name)
end
def queue_existing_for_delete #:nodoc:
def queue_some_for_delete(*styles)
@queued_for_delete += styles.uniq.map do |style|
path(style) if exists?(style)
end.compact
end
def queue_all_for_delete #:nodoc:
return if @options[:preserve_files] || !file?
@queued_for_delete += [:original, *styles.keys].uniq.map do |style|
path(style) if exists?(style)
......
......@@ -28,7 +28,7 @@ module Paperclip
def prepare_for_destroy
Paperclip.log("Scheduling attachments for deletion.")
each_attachment do |name, attachment|
attachment.send(:queue_existing_for_delete)
attachment.send(:queue_all_for_delete)
end
end
end
......
......@@ -19,6 +19,26 @@ class AttachmentTest < Test::Unit::TestCase
file.close
end
should "not delete styles that don't get reprocessed" do
file = File.new(File.join(File.dirname(__FILE__), "fixtures", "50x50.png"), 'rb')
rebuild_class :styles => { :small => '100x>',
:large => '500x>',
:original => '42x42#' }
dummy = Dummy.new
dummy.avatar = file
dummy.save
assert File.exists?(dummy.avatar.path(:small))
assert File.exists?(dummy.avatar.path(:large))
assert File.exists?(dummy.avatar.path(:original))
dummy.avatar.reprocess!(:small)
assert File.exists?(dummy.avatar.path(:small))
assert File.exists?(dummy.avatar.path(:large))
assert File.exists?(dummy.avatar.path(:original))
end
should "handle a boolean second argument to #url" do
mock_url_generator_builder = MockUrlGeneratorBuilder.new
attachment = Paperclip::Attachment.new(:name, :instance, :url_generator => mock_url_generator_builder)
......
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