Sha256: e7223c893ad1bf3d2380fe9782ca5fd6498b3f1d28571291d6cc133860d930c7

Contents?: true

Size: 958 Bytes

Versions: 3

Compression:

Stored size: 958 Bytes

Contents

require 'spec_helper'
require 'tempfile'

describe FileValidators::Utils::ContentTypeDetector do
  it 'returns the empty content type when the file is empty' do
    tempfile = Tempfile.new('empty')
    expect(described_class.new(tempfile.path, tempfile.path).detect).to eql('inode/x-empty')
    tempfile.close
  end

  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
    expect(described_class.new(tempfile.path, tempfile.path).detect).to eql('text/plain')
    tempfile.close
  end

  it 'returns a sensible default when the file path is empty' do
    expect(described_class.new('', '').detect).to eql('application/octet-stream')
  end

  it 'returns a sensible default if the file path is invalid' do
    file_path = '/path/to/nothing'
    expect(described_class.new(file_path, file_path).detect).to eql('application/octet-stream')
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
file_validators-2.3.0 spec/lib/file_validators/utils/content_type_detector_spec.rb
file_validators-2.2.0.beta1 spec/lib/file_validators/utils/content_type_detector_spec.rb
file_validators-2.1.0 spec/lib/file_validators/utils/content_type_detector_spec.rb