Welcome to mirror list, hosted at ThFree Co, Russian Federation.

mime_type_spec.rb « utils « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b2b6bd6c4e310c447eeb2e9694ef74534b80771f (plain)
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
48
49
50
51
52
53
54
55
56
57
# frozen_string_literal: true

require "fast_spec_helper"
require "rspec/parameterized"

RSpec.describe Gitlab::Utils::MimeType do
  describe ".from_io" do
    subject { described_class.from_io(io) }

    context "input isn't an IO" do
      let(:io) { "test" }

      it "returns nil" do
        expect(subject).to be_nil
      end
    end

    context "input is a file" do
      using RSpec::Parameterized::TableSyntax

      where(:fixture, :mime_type) do
        "banana_sample.gif"          | "image/gif"
        "rails_sample.jpg"           | "image/jpeg"
        "rails_sample.png"           | "image/png"
        "rails_sample.bmp"           | "image/bmp"
        "rails_sample.tif"           | "image/tiff"
        "sample.ico"                 | "image/vnd.microsoft.icon"
        "blockquote_fence_before.md" | "text/plain"
        "csv_empty.csv"              | "application/x-empty"
      end

      with_them do
        let(:io) { File.open(File.join(__dir__, "../../../fixtures", fixture)) }

        it { is_expected.to eq(mime_type) }
      end
    end
  end

  describe ".from_string" do
    subject { described_class.from_string(str) }

    context "input isn't a string" do
      let(:str) { nil }

      it "returns nil" do
        expect(subject).to be_nil
      end
    end

    context "input is a string" do
      let(:str) { "plain text" }

      it { is_expected.to eq('text/plain') }
    end
  end
end