diff --git a/lib/rack/test/uploaded_file.rb b/lib/rack/test/uploaded_file.rb index cb68bd83..d77fa353 100644 --- a/lib/rack/test/uploaded_file.rb +++ b/lib/rack/test/uploaded_file.rb @@ -71,8 +71,9 @@ def initialize_from_file_path(path) raise "#{path} file does not exist" unless ::File.exist?(path) @original_filename = ::File.basename(path) + extension = ::File.extname(@original_filename) - @tempfile = Tempfile.new([@original_filename, ::File.extname(path)]) + @tempfile = Tempfile.new([::File.basename(@original_filename, extension), extension]) @tempfile.set_encoding(Encoding::BINARY) if @tempfile.respond_to?(:set_encoding) ObjectSpace.define_finalizer(self, self.class.finalize(@tempfile)) diff --git a/spec/rack/test/uploaded_file_spec.rb b/spec/rack/test/uploaded_file_spec.rb index d558f64b..84d09f83 100644 --- a/spec/rack/test/uploaded_file_spec.rb +++ b/spec/rack/test/uploaded_file_spec.rb @@ -25,6 +25,13 @@ def test_file_path expect(File.extname(uploaded_file.path)).to eq('.txt') end + it 'creates Tempfiles with a path that includes a single extension' do + uploaded_file = Rack::Test::UploadedFile.new(test_file_path) + + regex = /foo#{Time.now.year}.*\.txt\Z/ + expect(uploaded_file.path).to match(regex) + end + context 'it should call its destructor' do it 'calls the destructor' do expect(Rack::Test::UploadedFile).to receive(:actually_finalize).at_least(:once)