Commit 41da3a3c by Jon Yurek

Make sure FileAdapter files have the right extension

parent 4b318160
......@@ -2,7 +2,6 @@ module Paperclip
class StringioAdapter < AbstractAdapter
def initialize(target)
@target = target
@tempfile = copy_to_tempfile
cache_current_values
end
......@@ -11,15 +10,15 @@ module Paperclip
private
def cache_current_values
self.original_filename = @target.original_filename if @target.respond_to?(:original_filename)
self.original_filename ||= "data"
@tempfile = copy_to_tempfile(@target)
@content_type = ContentTypeDetector.new(@tempfile.path).detect
original_filename = @target.original_filename if @target.respond_to?(:original_filename)
original_filename ||= "data"
self.original_filename = original_filename.strip
@size = @target.size
end
def copy_to_tempfile
while data = @target.read(16*1024)
def copy_to_tempfile(source)
while data = source.read(16*1024)
destination.write(data)
end
destination.rewind
......
......@@ -65,7 +65,6 @@ describe Paperclip::AbstractAdapter do
it 'uses the original filename to generate the tempfile' do
@adapter = TestAdapter.new
@adapter.original_filename = "file.png"
require 'pry'; binding.pry
expect(@adapter.send(:destination).path).to end_with(".png")
end
end
......@@ -18,6 +18,10 @@ describe Paperclip::FileAdapter do
@subject = Paperclip.io_adapters.for(@file)
end
it 'uses the original filename to generate the tempfile' do
assert @subject.path.ends_with?(".png")
end
it "gets the right filename" do
assert_equal "5k.png", @subject.original_filename
end
......
......@@ -56,6 +56,5 @@ describe Paperclip::StringioAdapter do
@subject.original_filename = 'image:restricted.png'
expect(@subject.path).to_not match(/:/)
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment