Sha256: c058c84b0ddac9d648f8575d5439e743e9857b2ba51385ccf13f96cebd22e294

Contents?: true

Size: 1.62 KB

Versions: 10

Compression:

Stored size: 1.62 KB

Contents

require 'spec_helper'

describe Paperclip::ContentTypeDetector do
  it 'gives a sensible default when the name is empty' do
    assert_equal "application/octet-stream", Paperclip::ContentTypeDetector.new("").detect
  end

  it 'returns the empty content type when the file is empty' do
    tempfile = Tempfile.new("empty")
    assert_equal "inode/x-empty", Paperclip::ContentTypeDetector.new(tempfile.path).detect
    tempfile.close
  end

  it 'returns content type of file if it is an acceptable type' do
    MIME::Types.stubs(:type_for).returns([MIME::Type.new('application/mp4'), MIME::Type.new('video/mp4'), MIME::Type.new('audio/mp4')])
    Paperclip.stubs(:run).returns("video/mp4")
    @filename = "my_file.mp4"
    assert_equal "video/mp4", Paperclip::ContentTypeDetector.new(@filename).detect
  end

  it 'finds the right type in the list via the file command' do
    @filename = "#{Dir.tmpdir}/something.hahalolnotreal"
    File.open(@filename, "w+") do |file|
      file.puts "This is a text file."
      file.rewind
      assert_equal "text/plain", Paperclip::ContentTypeDetector.new(file.path).detect
    end
    FileUtils.rm @filename
  end

  it 'returns a sensible default if something is wrong, like the file is gone' do
    @filename = "/path/to/nothing"
    assert_equal "application/octet-stream", Paperclip::ContentTypeDetector.new(@filename).detect
  end

  it 'returns 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

Version data entries

10 entries across 8 versions & 2 rubygems

Version Path
solidus_backend-1.0.0.pre3 vendor/bundle/gems/paperclip-4.2.4/spec/paperclip/content_type_detector_spec.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/paperclip-4.2.4/spec/paperclip/content_type_detector_spec.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/paperclip-4.2.2/spec/paperclip/content_type_detector_spec.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/paperclip-4.2.3/spec/paperclip/content_type_detector_spec.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/paperclip-4.2.4/spec/paperclip/content_type_detector_spec.rb
paperclip-4.2.4 spec/paperclip/content_type_detector_spec.rb
paperclip-4.2.3 spec/paperclip/content_type_detector_spec.rb
paperclip-4.2.2 spec/paperclip/content_type_detector_spec.rb
paperclip-4.2.1 spec/paperclip/content_type_detector_spec.rb
paperclip-4.2.0 spec/paperclip/content_type_detector_spec.rb