Skip to content

Commit

Permalink
Merge pull request #129 from szalansky/fix_creation_of_tempfiles
Browse files Browse the repository at this point in the history
Fix creation of tempfiles in Rack::Test::UploadedFile
  • Loading branch information
brynary committed Jul 3, 2015
2 parents 56ddeda + 5f78451 commit 0cd8537
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rack/test/uploaded_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions spec/rack/test/uploaded_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0cd8537

Please sign in to comment.