Sha256: bbeb0e85e43bedf23b4bf65e6d025a42e7c6c37de04543cadc733b681f959cbb

Contents?: true

Size: 1.79 KB

Versions: 42

Compression:

Stored size: 1.79 KB

Contents

require 'minitest/autorun'
require 'rack/mime'

describe Rack::Mime do

  it "should return the fallback mime-type for files with no extension" do
    fallback = 'image/jpg'
    Rack::Mime.mime_type(File.extname('no_ext'), fallback).must_equal fallback
  end

  it "should always return 'application/octet-stream' for unknown file extensions" do
    unknown_ext = File.extname('unknown_ext.abcdefg')
    Rack::Mime.mime_type(unknown_ext).must_equal 'application/octet-stream'
  end

  it "should return the mime-type for a given extension" do
    # sanity check. it would be infeasible test every single mime-type.
    Rack::Mime.mime_type(File.extname('image.jpg')).must_equal 'image/jpeg'
  end

  it "should support null fallbacks" do
    Rack::Mime.mime_type('.nothing', nil).must_be_nil
  end

  it "should match exact mimes" do
    Rack::Mime.match?('text/html', 'text/html').must_equal true
    Rack::Mime.match?('text/html', 'text/meme').must_equal false
    Rack::Mime.match?('text', 'text').must_equal true
    Rack::Mime.match?('text', 'binary').must_equal false
  end

  it "should match class wildcard mimes" do
    Rack::Mime.match?('text/html', 'text/*').must_equal true
    Rack::Mime.match?('text/plain', 'text/*').must_equal true
    Rack::Mime.match?('application/json', 'text/*').must_equal false
    Rack::Mime.match?('text/html', 'text').must_equal true
  end

  it "should match full wildcards" do
    Rack::Mime.match?('text/html', '*').must_equal true
    Rack::Mime.match?('text/plain', '*').must_equal true
    Rack::Mime.match?('text/html', '*/*').must_equal true
    Rack::Mime.match?('text/plain', '*/*').must_equal true
  end

  it "should match type wildcard mimes" do
    Rack::Mime.match?('text/html', '*/html').must_equal true
    Rack::Mime.match?('text/plain', '*/plain').must_equal true
  end

end

Version data entries

42 entries across 40 versions & 10 rubygems

Version Path
rack-2.0.9.4 test/spec_mime.rb
rack-2.0.9.3 test/spec_mime.rb
rack-2.0.9.2 test/spec_mime.rb
rack-2.0.9.1 test/spec_mime.rb
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/gems/rack-2.0.5/test/spec_mime.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rack-2.0.8/test/spec_mime.rb
tdiary-5.1.2 vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/test/spec_mime.rb
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/rack-2.0.6/test/spec_mime.rb
tdiary-5.1.1 vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/test/spec_mime.rb
rack-2.0.9 test/spec_mime.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/rack-2.0.8/test/spec_mime.rb
rack-2.0.8 test/spec_mime.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rack-2.0.7/test/spec_mime.rb
tdiary-5.1.0 vendor/bundle/gems/rack-2.0.7/test/spec_mime.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rack-2.0.7/test/spec_mime.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/rack-2.0.7/test/spec_mime.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/rack-2.0.7/test/spec_mime.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/rack-2.0.7/test/spec_mime.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/rack-2.0.7/test/spec_mime.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/rack-2.0.7/test/spec_mime.rb