diff --git a/lib/rack/test/uploaded_file.rb b/lib/rack/test/uploaded_file.rb index d0d3e2a8..33394127 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 diff --git a/spec/rack/test/uploaded_file_spec.rb b/spec/rack/test/uploaded_file_spec.rb index cde48567..8ffafc66 100644 --- a/spec/rack/test/uploaded_file_spec.rb +++ b/spec/rack/test/uploaded_file_spec.rb @@ -21,4 +21,9 @@ def test_file_path uploaded_file.should respond_to(:tempfile) # Allows calls to params[:file].tempfile end + it "creates Tempfiles with original file's extension" do + uploaded_file = Rack::Test::UploadedFile.new(test_file_path) + + File.extname(uploaded_file.path).should eq(".txt") + end end