Commit c64223c6 by Jon Yurek

Fixed an error where ImageMagick wasn't identifying images because the Tempfiles…

Fixed an error where ImageMagick wasn't identifying images because the Tempfiles did not have the right extension.
parent 68286d68
...@@ -4,7 +4,8 @@ module IOStream ...@@ -4,7 +4,8 @@ module IOStream
# Returns a Tempfile containing the contents of the readable object. # Returns a Tempfile containing the contents of the readable object.
def to_tempfile def to_tempfile
tempfile = Tempfile.new("stream") name = respond_to?(:original_filename) ? original_filename : (respond_to?(:path) ? path : "stream")
tempfile = Paperclip::Tempfile.new(File.basename(name))
tempfile.binmode tempfile.binmode
self.stream_to(tempfile) self.stream_to(tempfile)
end end
......
...@@ -133,7 +133,7 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -133,7 +133,7 @@ class AttachmentTest < Test::Unit::TestCase
:styles => { :default => ["100x100", :png] }, :styles => { :default => ["100x100", :png] },
:default_style => :default :default_style => :default
@file = StringIO.new("...") @file = StringIO.new("...")
@file.expects(:original_filename).returns("file.jpg") @file.stubs(:original_filename).returns("file.jpg")
end end
should "return the right extension for the path" do should "return the right extension for the path" do
@attachment.assign(@file) @attachment.assign(@file)
......
...@@ -3,7 +3,7 @@ require 'test/unit' ...@@ -3,7 +3,7 @@ require 'test/unit'
require 'shoulda' require 'shoulda'
require 'tempfile' require 'tempfile'
gem 'jferris-mocha', '0.9.5.0.1241126838' gem 'jferris-mocha'
require 'mocha' require 'mocha'
gem 'sqlite3-ruby' gem 'sqlite3-ruby'
......
...@@ -58,8 +58,15 @@ class IOStreamTest < Test::Unit::TestCase ...@@ -58,8 +58,15 @@ class IOStreamTest < Test::Unit::TestCase
assert @tempfile = @file.to_tempfile assert @tempfile = @file.to_tempfile
end end
should "convert it to a Tempfile" do should "convert it to a Paperclip Tempfile" do
assert @tempfile.is_a?(Tempfile) assert @tempfile.is_a?(Paperclip::Tempfile)
end
should "have the name be based on the original_filename" do
name = File.basename(@file.path)
extension = File.extname(name)
basename = File.basename(name, extension)
assert_match %r[^#{Regexp.quote(basename)}.*?#{Regexp.quote(extension)}], File.basename(@tempfile.path)
end end
should "have the Tempfile contain the same data as the file" do should "have the Tempfile contain the same data as the file" do
......
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