Skip to content

Commit

Permalink
Handle unlinked tempfiles in Shrine#upload
Browse files Browse the repository at this point in the history
Fixes #563
  • Loading branch information
janko committed Feb 19, 2022
1 parent b0f5624 commit d21556f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/shrine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def _upload(io, location:, metadata:, upload_options: {}, close: true, delete: f
def extract_filename(io)
if io.respond_to?(:original_filename)
io.original_filename
elsif io.respond_to?(:path)
elsif io.respond_to?(:path) && io.path
File.basename(io.path)
end
end
Expand Down
7 changes: 7 additions & 0 deletions test/shrine_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,13 @@ def respond_to_missing?(name, include_private = false)

@uploader.upload(io)
end

it "supports unlinked tempfiles" do
tempfile = Tempfile.new
tempfile.unlink

assert_kind_of Shrine::UploadedFile, @uploader.upload(tempfile)
end
end

describe "#generate_location" do
Expand Down

0 comments on commit d21556f

Please sign in to comment.