Sha256: 8b22f8f72056837395d8eac88e7b11c0ade497ae8b18bb9a262b637338f8117d

Contents?: true

Size: 1.27 KB

Versions: 10

Compression:

Stored size: 1.27 KB

Contents

require 'spec_helper'

describe Hydra::Works::DetermineMimeType do
  let(:original_name) { nil }
  let(:file) { File.open(File.join(fixture_path, 'sample-file.pdf')) }

  subject { described_class.call(file, original_name) }

  context "when file has :mime_type" do
    before { allow(file).to receive(:mime_type).and_return("mime_type") }
    it { is_expected.to eq("mime_type") }
  end

  context "when file has :content_type" do
    before { allow(file).to receive(:content_type).and_return("content_type") }
    it { is_expected.to eq("content_type") }
  end

  context "when file has :path" do
    it { is_expected.to eq("application/pdf") }
  end

  context "when an original_name is supplied" do
    let(:original_name) { "some-other-file.txt" }
    it { is_expected.to eq("text/plain") }
  end

  context "when an empty original_name is supplied" do
    let(:original_name) { "" }
    it { is_expected.to eq("application/pdf") }
  end

  context "when all else fails" do
    before do
      allow(file).to receive(:respond_to?).with(:mime_type).and_return(false)
      allow(file).to receive(:respond_to?).with(:content_type).and_return(false)
      allow(file).to receive(:respond_to?).with(:path).and_return(false)
    end
    it { is_expected.to eq("application/octet-stream") }
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
hydra-works-2.2.0 spec/hydra/works/services/determine_mime_type_spec.rb
hydra-works-2.1.0 spec/hydra/works/services/determine_mime_type_spec.rb
hydra-works-2.0.0 spec/hydra/works/services/determine_mime_type_spec.rb
hydra-works-1.2.0 spec/hydra/works/services/determine_mime_type_spec.rb
hydra-works-1.1.0 spec/hydra/works/services/determine_mime_type_spec.rb
hydra-works-1.0.0 spec/hydra/works/services/determine_mime_type_spec.rb
hydra-works-0.17.0 spec/hydra/works/services/determine_mime_type_spec.rb
hydra-works-0.16.0 spec/hydra/works/services/determine_mime_type_spec.rb
hydra-works-0.15.0 spec/hydra/works/services/determine_mime_type_spec.rb
hydra-works-0.14.0 spec/hydra/works/services/determine_mime_type_spec.rb