Commit f820685d by Michael Dotterer Committed by Jon Yurek

Reset instance attributes when clearing attachment with preserve_files

parent 30080c4a
......@@ -233,11 +233,9 @@ module Paperclip
# nil to the attachment *and saving*. This is permanent. If you wish to
# wipe out the existing attachment but not save, use #clear.
def destroy
unless @options[:preserve_files]
clear
save
end
end
# Returns the uploaded file if present.
def uploaded_file
......@@ -454,10 +452,12 @@ module Paperclip
end
def queue_all_for_delete #:nodoc:
return if @options[:preserve_files] || !file?
return if !file?
unless @options[:preserve_files]
@queued_for_delete += [:original, *styles.keys].uniq.map do |style|
path(style) if exists?(style)
end.compact
end
instance_write(:file_name, nil)
instance_write(:content_type, nil)
instance_write(:file_size, nil)
......
......@@ -1324,6 +1324,12 @@ class AttachmentTest < Test::Unit::TestCase
assert_file_exists(@path)
end
should "clear out attachment data when attachment is destroyed" do
@attachment.destroy
assert !@attachment.exists?
assert_nil @dummy.avatar_file_name
end
should "not delete the file when model is destroyed" do
@dummy.destroy
assert_file_exists(@path)
......
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