Sha256: e1b01395a4653f061f012467018d05b187b814aa8af9ccb5f3eebd13476e3bac

Contents?: true

Size: 1.37 KB

Versions: 4

Compression:

Stored size: 1.37 KB

Contents

require 'spec_helper'

describe Paperclip::FileCommandContentTypeDetector do
  it 'returns 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::FileCommandContentTypeDetector.new(tempfile.path).detect

    tempfile.close
  end

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

  it 'returns a sensible default on the odd chance that run returns nil' do
    Paperclip.stubs(:run).returns(nil)
    assert_equal "application/octet-stream",
      Paperclip::FileCommandContentTypeDetector.new("windows").detect
  end

  context "#type_from_file_command" do
    let(:detector) { Paperclip::FileCommandContentTypeDetector.new("html") }

    it "does work with the output of old versions of file" do
      Paperclip.stubs(:run).returns("text/html charset=us-ascii")
      expect(detector.detect).to eq("text/html")
    end

    it "does work with the output of new versions of file" do
      Paperclip.stubs(:run).returns("text/html; charset=us-ascii")
      expect(detector.detect).to eq("text/html")
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
kt-paperclip-5.4.0 spec/paperclip/file_command_content_type_detector_spec.rb
paperclip-6.1.0 spec/paperclip/file_command_content_type_detector_spec.rb
paperclip-6.0.0 spec/paperclip/file_command_content_type_detector_spec.rb
paperclip-5.3.0 spec/paperclip/file_command_content_type_detector_spec.rb