diff --git a/lib/paperclip/io_adapters/file_adapter.rb b/lib/paperclip/io_adapters/file_adapter.rb index 6109bf760..f50409719 100644 --- a/lib/paperclip/io_adapters/file_adapter.rb +++ b/lib/paperclip/io_adapters/file_adapter.rb @@ -63,7 +63,7 @@ def copy_to_tempfile(src) end def best_content_type_option(types) - types.reject {|type| type.content_type.match(/\/x-/) }.first + types.reject {|type| type.content_type.match(/\/x-/) }.first.content_type end def type_from_file_command diff --git a/test/file_adapter_test.rb b/test/file_adapter_test.rb index 6fb93ee25..e3ddb43a4 100644 --- a/test/file_adapter_test.rb +++ b/test/file_adapter_test.rb @@ -23,6 +23,10 @@ class FileAdapterTest < Test::Unit::TestCase assert_equal "image/png", @subject.content_type end + should "return content type as a string" do + assert_kind_of String, @subject.content_type + end + should "get the file's size" do assert_equal 4456, @subject.size end @@ -41,6 +45,20 @@ class FileAdapterTest < Test::Unit::TestCase assert expected.length > 0 assert_equal expected, @subject.read end + + context "file with multiple possible content type" do + setup do + MIME::Types.stubs(:type_for).returns([MIME::Type.new('image/x-png'), MIME::Type.new('image/png')]) + end + + should "prefer officially registered mime type" do + assert_equal "image/png", @subject.content_type + end + + should "return content type as a string" do + assert_kind_of String, @subject.content_type + end + end end context "empty file" do