Skip to content

Commit

Permalink
Call #content_type on MimeType object
Browse files Browse the repository at this point in the history
This will ensure that the content type is a String.

Fixes thoughtbot#805
  • Loading branch information
sikachu committed Apr 17, 2012
1 parent 4f6d482 commit 3f1d30f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/paperclip/io_adapters/file_adapter.rb
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions test/file_adapter_test.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 3f1d30f

Please sign in to comment.