Sha256: 80deb46b439e50fdc845cadccab0880ff08e31742a290cd622b44dec2cb2c675

Contents?: true

Size: 1.46 KB

Versions: 9

Compression:

Stored size: 1.46 KB

Contents

require './test/helper'

class ContentTypeDetectorTest < Test::Unit::TestCase
  context 'given a name' do
    should 'return a content type based on that name' do
      @filename = "/path/to/something.jpg"
      assert_equal "image/jpeg", Paperclip::ContentTypeDetector.new(@filename).detect
    end

    should 'return a content type based on the content of the file' do
      tempfile = Tempfile.new("something")
      tempfile.write("This is a file.")
      tempfile.rewind

      assert_equal "text/plain", Paperclip::ContentTypeDetector.new(tempfile.path).detect
    end

    should 'return an empty content type if the file is empty' do
      tempfile = Tempfile.new("something")
      tempfile.rewind

      assert_equal "inode/x-empty", Paperclip::ContentTypeDetector.new(tempfile.path).detect
    end

    should 'return a sensible default if no filename is supplied' do
      assert_equal "application/octet-stream", Paperclip::ContentTypeDetector.new('').detect
    end

    should 'return a sensible default if something goes wrong' do
      @filename = "/path/to/something"
      assert_equal "application/octet-stream", Paperclip::ContentTypeDetector.new(@filename).detect
    end

    should 'return a sensible default when the file command is missing' do
      Paperclip.stubs(:run).raises(Cocaine::CommandLineError.new)
      @filename = "/path/to/something"
      assert_equal "application/octet-stream", Paperclip::ContentTypeDetector.new(@filename).detect
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
paperclip-3.5.0 test/content_type_detector_test.rb
paperclip-3.4.2 test/content_type_detector_test.rb
paperclip-3.4.1 test/content_type_detector_test.rb
paperclip-3.4.0 test/content_type_detector_test.rb
paperclip-3.3.1 test/content_type_detector_test.rb
paperclip-3.2.1 test/content_type_detector_test.rb
paperclip-3.3.0 test/content_type_detector_test.rb
paperclip-3.2.0 test/content_type_detector_test.rb
paperclip-3.1.4 test/content_type_detector_test.rb