Commit e705b737 by Jon Yurek

Don't delete all the existing styles if we reprocess

parent a596c01b
...@@ -90,7 +90,7 @@ module Paperclip ...@@ -90,7 +90,7 @@ module Paperclip
ensure_required_accessors! ensure_required_accessors!
file = Paperclip.io_adapters.for(uploaded_file) file = Paperclip.io_adapters.for(uploaded_file)
self.clear self.clear(*@options[:only_process])
return nil if file.nil? return nil if file.nil?
@queued_for_write[:original] = file @queued_for_write[:original] = file
...@@ -202,11 +202,15 @@ module Paperclip ...@@ -202,11 +202,15 @@ module Paperclip
# Clears out the attachment. Has the same effect as previously assigning # 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, # nil to the attachment. Does NOT save. If you wish to clear AND save,
# use #destroy. # use #destroy.
def clear def clear(*styles_to_clear)
queue_existing_for_delete if styles_to_clear.any?
queue_some_for_delete(*styles_to_clear)
else
queue_all_for_delete
@queued_for_write = {} @queued_for_write = {}
@errors = {} @errors = {}
end end
end
# Destroys the attachment. Has the same effect as previously assigning # Destroys the attachment. Has the same effect as previously assigning
# nil to the attachment *and saving*. This is permanent. If you wish to # nil to the attachment *and saving*. This is permanent. If you wish to
...@@ -406,7 +410,13 @@ module Paperclip ...@@ -406,7 +410,13 @@ module Paperclip
interpolator.interpolate(pattern, self, style_name) interpolator.interpolate(pattern, self, style_name)
end 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? return if @options[:preserve_files] || !file?
@queued_for_delete += [:original, *styles.keys].uniq.map do |style| @queued_for_delete += [:original, *styles.keys].uniq.map do |style|
path(style) if exists?(style) path(style) if exists?(style)
......
...@@ -28,7 +28,7 @@ module Paperclip ...@@ -28,7 +28,7 @@ module Paperclip
def prepare_for_destroy def prepare_for_destroy
Paperclip.log("Scheduling attachments for deletion.") Paperclip.log("Scheduling attachments for deletion.")
each_attachment do |name, attachment| each_attachment do |name, attachment|
attachment.send(:queue_existing_for_delete) attachment.send(:queue_all_for_delete)
end end
end end
end end
......
...@@ -19,6 +19,26 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -19,6 +19,26 @@ class AttachmentTest < Test::Unit::TestCase
file.close file.close
end 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 should "handle a boolean second argument to #url" do
mock_url_generator_builder = MockUrlGeneratorBuilder.new mock_url_generator_builder = MockUrlGeneratorBuilder.new
attachment = Paperclip::Attachment.new(:name, :instance, :url_generator => mock_url_generator_builder) 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