Commit c1b35778 by Andrew Pollok

Fixed a bug whereby a file type with multiple mime types but no official type

would cause the best_content_type to throw an error on trying nil.content_type.
parent 5bf0619f
......@@ -65,7 +65,12 @@ module Paperclip
end
def best_content_type_option(types)
types.reject {|type| type.content_type.match(/\/x-/) }.first.content_type
best = types.reject {|type| type.content_type.match(/\/x-/) }
if best.size == 0
types.first.content_type
else
best.first.content_type
end
end
def type_from_file_command
......
......@@ -60,6 +60,16 @@ class FileAdapterTest < Test::Unit::TestCase
end
end
context "file with multiple possible x-types but no official type" do
setup do
MIME::Types.stubs(:type_for).returns([MIME::Type.new('image/x-mp4'), MIME::Type.new('image/x-video')])
end
should "return the last" do
assert_equal "image/x-mp4", @subject.content_type
end
end
context "file with content type derived from file command on *nix" do
setup do
MIME::Types.stubs(:type_for).returns([])
......
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