Commit 87bd86cc by Jon Yurek

Resolved mvanholstyn's open file fixes with current code

parent f79dadce
......@@ -186,9 +186,9 @@ module Paperclip
begin
dimensions, format = args
@queued_for_write[name] = Thumbnail.make(@queued_for_write[:original],
dimensions,
format,
@whiny_thumnails)
dimensions,
format,
@whiny_thumnails)
rescue Errno::ENOENT => e
@errors << "could not be processed because the file does not exist."
rescue PaperclipError => e
......
......@@ -16,7 +16,7 @@ module Paperclip
# Returns representation of the data of the file assigned to the given
# style, in the format most representative of the current storage.
def to_file style = default_style
File.new(path(style)) if exists?(style)
@queued_for_write[style] || (File.new(path(style)) if exists?(style))
end
alias_method :to_io, :to_file
......@@ -35,7 +35,7 @@ module Paperclip
begin
FileUtils.rm(path) if File.exist?(path)
rescue Errno::ENOENT => e
# ignore them
# ignore file-not-found, let everything else pass
end
end
@queued_for_delete = []
......@@ -74,7 +74,7 @@ module Paperclip
# Returns representation of the data of the file assigned to the given
# style, in the format most representative of the current storage.
def to_file style = default_style
@s3_bucket.key(path(style))
@queued_for_write[style] || @s3_bucket.key(path(style))
end
alias_method :to_io, :to_file
......
def obtain_class
class_name = ENV['CLASS'] || ENV['class']
raise "Must specify CLASS" unless class_name
@klass = Object.const_get(class_name)
end
def obtain_attachments
name = ENV['ATTACHMENT'] || ENV['attachment']
raise "Class #{@klass.name} has no attachments specified" unless @klass.respond_to?(:attachment_names)
if !name.blank? && @klass.attachment_names.include?(name)
[ name ]
else
......@@ -16,11 +18,10 @@ namespace :paperclip do
desc "Regenerates thumbnails for a given CLASS (and optional ATTACHMENT)"
task :refresh => :environment do
klass = obtain_class
instances = klass.find(:all)
names = obtain_attachments
puts "Regenerating thumbnails for #{instances.length} instances of #{klass.name}:"
instances.each do |instance|
klass.find(:all).each do |instance|
names.each do |name|
result = if instance.send("#{ name }?")
instance.send(name).send("post_process")
......
......@@ -195,23 +195,6 @@ class AttachmentTest < Test::Unit::TestCase
@existing_names.each{|f| assert ! File.exists?(f) }
end
end
context "and deleted" do
setup do
@existing_names = @attachment.styles.keys.collect do |style|
@attachment.path(style)
end
@instance.expects(:[]=).with(:test_file_name, nil)
@instance.expects(:[]=).with(:test_content_type, nil)
@instance.expects(:[]=).with(:test_file_size, nil)
@attachment.assign nil
@attachment.save
end
should "delete the files" do
@existing_names.each{|f| assert ! File.exists?(f) }
end
end
end
end
end
......
......@@ -223,7 +223,7 @@ class IntegrationTest < Test::Unit::TestCase
expected = @dummy.avatar.to_file
@dummy.avatar = "not a file"
assert @dummy.valid?
assert_equal expected, @dummy.avatar.to_file
assert_equal expected.full_name, @dummy.avatar.to_file.full_name
@dummy.avatar = @bad_file
assert ! @dummy.valid?
......
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