Commit 511f3bc9 by Mark Guk Committed by Tute Costa

Bugfix for when file is not present on cloud

Currently paperclip fails with `NoMethodError` on `nil` when file is not
present. Since `nil` is proper response from fog on missing files, and
this method already returns `false` if any error happen (see line 178),
returning `false` here would be properly handled on client code.

[closes #2173]
parent 26a4f4fc
......@@ -170,6 +170,7 @@ module Paperclip
log("copying #{path(style)} to local file #{local_dest_path}")
::File.open(local_dest_path, 'wb') do |local_file|
file = directory.files.get(path(style))
return false unless file
local_file.write(file.body)
end
rescue ::Fog::Errors::Error => e
......
......@@ -183,6 +183,13 @@ describe Paperclip::Storage::Fog do
tempfile.close
end
it 'is able to be handled when missing while copying to a local file' do
tempfile = Tempfile.new("known_location")
tempfile.binmode
assert_equal false, @dummy.avatar.copy_to_local_file(:original, tempfile.path)
tempfile.close
end
it "passes the content type to the Fog::Storage::AWS::Files instance" do
Fog::Storage::AWS::Files.any_instance.expects(:create).with do |hash|
hash[:content_type]
......
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