Commit 8b778b30 by Jon Yurek

Enforce saving content_type as a string with test

parent e59d0b53
......@@ -95,7 +95,7 @@ module Paperclip
@queued_for_write[:original] = file
instance_write(:file_name, cleanup_filename(file.original_filename))
instance_write(:content_type, file.content_type)
instance_write(:content_type, file.content_type.to_s.strip)
instance_write(:file_size, file.size)
instance_write(:fingerprint, file.fingerprint) if instance_respond_to?(:fingerprint)
instance_write(:updated_at, Time.now)
......
......@@ -16,7 +16,7 @@ module Paperclip
def content_type
@content_type ||= @target.content_type if @target.respond_to?(:content_type)
@content_type ||= "text/plain"
@content_type.strip
@content_type
end
def size
......
......@@ -691,6 +691,21 @@ class AttachmentTest < Test::Unit::TestCase
end
end
context "Assigning an attachment" do
setup do
rebuild_model :styles => { :something => "100x100#" }
@file = StringIO.new(".")
@file.stubs(:original_filename).returns("5k.png\n\n")
@file.stubs(:content_type).returns(MIME::Type.new("image/png"))
@dummy = Dummy.new
@dummy.avatar = @file
end
should "make sure the content_type is a string" do
assert_equal "image/png", @dummy.avatar.instance.avatar_content_type
end
end
context "Attachment with strange letters" do
setup do
rebuild_model
......
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