summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-03-26 17:34:57 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-03-26 17:34:57 +0000
commitb2ce3643e27db4cc0ad30cc09d651c00ec799887 (patch)
treef0e7882be8145da2f59fec4ac26e070afd147ab9 /spec/lib/gitlab
parente9143b15cc400b69ef274789225ac2fee5fdcf83 (diff)
downloadgitlab-ce-b2ce3643e27db4cc0ad30cc09d651c00ec799887.tar.gz
Add latest changes from gitlab-org/gitlab@13-10-stable-ee
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r--spec/lib/gitlab/utils/mime_type_spec.rb57
1 files changed, 57 insertions, 0 deletions
diff --git a/spec/lib/gitlab/utils/mime_type_spec.rb b/spec/lib/gitlab/utils/mime_type_spec.rb
new file mode 100644
index 00000000000..b2b6bd6c4e3
--- /dev/null
+++ b/spec/lib/gitlab/utils/mime_type_spec.rb
@@ -0,0 +1,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