Commit c7b84adc by Jason Morrison

Adding a unit test for Upfile and updating a few content types

parent d6ebd321
...@@ -8,12 +8,13 @@ module Paperclip ...@@ -8,12 +8,13 @@ module Paperclip
def content_type def content_type
type = (self.path.match(/\.(\w+)$/)[1] rescue "octet-stream").downcase type = (self.path.match(/\.(\w+)$/)[1] rescue "octet-stream").downcase
case type case type
when %r"jpe?g" then "image/jpeg" when %r"jp(e|g|eg)" then "image/jpeg"
when %r"tiff?" then "image/tiff" when %r"tiff?" then "image/tiff"
when %r"png", "gif", "bmp" then "image/#{type}" when %r"png", "gif", "bmp" then "image/#{type}"
when "txt" then "text/plain" when "txt" then "text/plain"
when %r"html?" then "text/html" when %r"html?" then "text/html"
when "csv", "xml", "css", "js" then "text/#{type}" when "js" then "application/js"
when "csv", "xml", "css" then "text/#{type}"
else "application/x-#{type}" else "application/x-#{type}"
end end
end end
......
require 'test/helper'
class UpfileTest < Test::Unit::TestCase
{ %w(jpg jpe jpeg) => 'image/jpeg',
%w(tif tiff) => 'image/tiff',
%w(png) => 'image/png',
%w(gif) => 'image/gif',
%w(bmp) => 'image/bmp',
%w(txt) => 'text/plain',
%w(htm html) => 'text/html',
%w(csv) => 'text/csv',
%w(xml) => 'text/xml',
%w(css) => 'text/css',
%w(js) => 'application/js',
%w(foo) => 'application/x-foo'
}.each do |extensions, content_type|
extensions.each do |extension|
should "return a content_type of #{content_type} for a file with extension .#{extension}" do
file = stub('file', :path => "basename.#{extension}")
class << file
include Paperclip::Upfile
end
assert_equal content_type, file.content_type
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