From fff392abc59c15427bec9105eb5f0f0bbda6cff9 Mon Sep 17 00:00:00 2001
From: Raf Szalanski <rafal.szalanski@gmail.com>
Date: Thu, 2 Jul 2015 22:31:40 +0000
Subject: [PATCH] Fix creation of tempfiles in Rack::Test::UploadedFile
Tempfile's initializer is not very intuitive. If you want your tempfile
to have an extension you have to pass an array with two elements:
- basename
- extension (with a dot at the beginning)
This change makes it behave more like original Rack::Multipart::UploadedFile.
---
lib/rack/test/uploaded_file.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/rack/test/uploaded_file.rb b/lib/rack/test/uploaded_file.rb
index d0d3e2a..3339412 100644
--- a/lib/rack/test/uploaded_file.rb
+++ b/lib/rack/test/uploaded_file.rb
@@ -26,7 +26,7 @@ def initialize(path, content_type = "text/plain", binary = false)
@content_type = content_type
@original_filename = ::File.basename(path)
- @tempfile = Tempfile.new(@original_filename)
+ @tempfile = Tempfile.new([@original_filename, ::File.extname(path)])
@tempfile.set_encoding(Encoding::BINARY) if @tempfile.respond_to?(:set_encoding)
@tempfile.binmode if binary