File: mime_type_test.rb

package info (click to toggle)
ruby-marcel 1.0.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 10,744 kB
  • sloc: xml: 7,041; ruby: 536; makefile: 7; javascript: 3
file content (47 lines) | stat: -rw-r--r-- 1,379 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require 'test_helper'
require 'rack'

class Marcel::MimeTypeTest < Marcel::TestCase
  def setup
    @path = files("image.gif").to_s
  end

  test "gets content type from Files" do
    content_type = File.open @path do |file|
      Marcel::MimeType.for file
    end
    assert_equal "image/gif", content_type
  end

  test "gets content type from Pathnames" do
    content_type = Marcel::MimeType.for Pathname.new(@path)
    assert_equal "image/gif", content_type
  end

  test "closes Pathname files after use" do
    content_type = Marcel::MimeType.for Pathname.new(@path)
    open_files = ObjectSpace.each_object(File).reject(&:closed?)
    assert open_files.none? { |f| f.path == @path }
  end

  test "gets content type from Tempfiles" do
    Tempfile.open("Marcel") do |tempfile|
      tempfile.write(File.read(@path))
      content_type = Marcel::MimeType.for tempfile
      assert_equal "image/gif", content_type
    end
  end

  test "gets content type from IOs" do
    io = StringIO.new(File.read(@path))
    content_type = Marcel::MimeType.for io
    assert_equal "image/gif", content_type
  end

  test "gets content type from sources that conform to Rack::Lint::InputWrapper" do
    io = StringIO.new(File.read(@path))
    wrapper = Rack::Lint::InputWrapper.new(io)
    content_type = Marcel::MimeType.for wrapper
    assert_equal "image/gif", content_type
  end
end