Commit 41da3a3c by Jon Yurek

Make sure FileAdapter files have the right extension

parent 4b318160
...@@ -2,7 +2,6 @@ module Paperclip ...@@ -2,7 +2,6 @@ module Paperclip
class StringioAdapter < AbstractAdapter class StringioAdapter < AbstractAdapter
def initialize(target) def initialize(target)
@target = target @target = target
@tempfile = copy_to_tempfile
cache_current_values cache_current_values
end end
...@@ -11,15 +10,15 @@ module Paperclip ...@@ -11,15 +10,15 @@ module Paperclip
private private
def cache_current_values 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 @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 @size = @target.size
end end
def copy_to_tempfile def copy_to_tempfile(source)
while data = @target.read(16*1024) while data = source.read(16*1024)
destination.write(data) destination.write(data)
end end
destination.rewind destination.rewind
......
...@@ -65,7 +65,6 @@ describe Paperclip::AbstractAdapter do ...@@ -65,7 +65,6 @@ describe Paperclip::AbstractAdapter do
it 'uses the original filename to generate the tempfile' do it 'uses the original filename to generate the tempfile' do
@adapter = TestAdapter.new @adapter = TestAdapter.new
@adapter.original_filename = "file.png" @adapter.original_filename = "file.png"
require 'pry'; binding.pry
expect(@adapter.send(:destination).path).to end_with(".png") expect(@adapter.send(:destination).path).to end_with(".png")
end end
end end
...@@ -18,6 +18,10 @@ describe Paperclip::FileAdapter do ...@@ -18,6 +18,10 @@ describe Paperclip::FileAdapter do
@subject = Paperclip.io_adapters.for(@file) @subject = Paperclip.io_adapters.for(@file)
end end
it 'uses the original filename to generate the tempfile' do
assert @subject.path.ends_with?(".png")
end
it "gets the right filename" do it "gets the right filename" do
assert_equal "5k.png", @subject.original_filename assert_equal "5k.png", @subject.original_filename
end end
......
...@@ -56,6 +56,5 @@ describe Paperclip::StringioAdapter do ...@@ -56,6 +56,5 @@ describe Paperclip::StringioAdapter do
@subject.original_filename = 'image:restricted.png' @subject.original_filename = 'image:restricted.png'
expect(@subject.path).to_not match(/:/) expect(@subject.path).to_not match(/:/)
end end
end 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