Sha256: 54dddb46a0d20b3cb986754f3775e379d9c71152fcb6c3e46052d72dc3cac630

Contents?: true

Size: 1.45 KB

Versions: 14

Compression:

Stored size: 1.45 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
    allow(Paperclip).to receive(:run).and_raise(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
    allow(Paperclip).to receive(:run).and_return(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
      allow(Paperclip).to receive(:run).and_return("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
      allow(Paperclip).to receive(:run).and_return("text/html; charset=us-ascii")
      expect(detector.detect).to eq("text/html")
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
kt-paperclip-7.2.2 spec/paperclip/file_command_content_type_detector_spec.rb
kt-paperclip-7.2.1 spec/paperclip/file_command_content_type_detector_spec.rb
kt-paperclip-7.2.0 spec/paperclip/file_command_content_type_detector_spec.rb
kt-paperclip-6.4.2 spec/paperclip/file_command_content_type_detector_spec.rb
kt-paperclip-7.1.1 spec/paperclip/file_command_content_type_detector_spec.rb
kt-paperclip-7.1.0 spec/paperclip/file_command_content_type_detector_spec.rb
kt-paperclip-7.0.1 spec/paperclip/file_command_content_type_detector_spec.rb
kt-paperclip-7.0.0 spec/paperclip/file_command_content_type_detector_spec.rb
kt-paperclip-6.4.1 spec/paperclip/file_command_content_type_detector_spec.rb
kt-paperclip-6.4.0 spec/paperclip/file_command_content_type_detector_spec.rb
kt-paperclip-6.3.0 spec/paperclip/file_command_content_type_detector_spec.rb
kt-paperclip-6.2.2 spec/paperclip/file_command_content_type_detector_spec.rb
kt-paperclip-6.2.1 spec/paperclip/file_command_content_type_detector_spec.rb
kt-paperclip-6.2.0 spec/paperclip/file_command_content_type_detector_spec.rb