Skip to content
This repository was archived by the owner on Jul 13, 2023. It is now read-only.

Commit 511f3bc

Browse files
vimuttertute
authored andcommitted
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]
1 parent 26a4f4f commit 511f3bc

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lib/paperclip/storage/fog.rb

+1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ def copy_to_local_file(style, local_dest_path)
170170
log("copying #{path(style)} to local file #{local_dest_path}")
171171
::File.open(local_dest_path, 'wb') do |local_file|
172172
file = directory.files.get(path(style))
173+
return false unless file
173174
local_file.write(file.body)
174175
end
175176
rescue ::Fog::Errors::Error => e

spec/paperclip/storage/fog_spec.rb

+7
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,13 @@ def custom_method
183183
tempfile.close
184184
end
185185

186+
it 'is able to be handled when missing while copying to a local file' do
187+
tempfile = Tempfile.new("known_location")
188+
tempfile.binmode
189+
assert_equal false, @dummy.avatar.copy_to_local_file(:original, tempfile.path)
190+
tempfile.close
191+
end
192+
186193
it "passes the content type to the Fog::Storage::AWS::Files instance" do
187194
Fog::Storage::AWS::Files.any_instance.expects(:create).with do |hash|
188195
hash[:content_type]

0 commit comments

Comments
 (0)