Sha256: c72d1d97181c1ae099859402e8e8eda9da5449d2684d85483a77f1720ecbef93

Contents?: true

Size: 1.47 KB

Versions: 13

Compression:

Stored size: 1.47 KB

Contents

require 'minitest/autorun'
require 'rack/content_type'
require 'rack/lint'
require 'rack/mock'

describe Rack::ContentType do
  def content_type(app, *args)
    Rack::Lint.new Rack::ContentType.new(app, *args)
  end

  def request
    Rack::MockRequest.env_for
  end

  it "set Content-Type to default text/html if none is set" do
    app = lambda { |env| [200, {}, "Hello, World!"] }
    headers = content_type(app).call(request)[1]
    headers['Content-Type'].must_equal 'text/html'
  end

  it "set Content-Type to chosen default if none is set" do
    app = lambda { |env| [200, {}, "Hello, World!"] }
    headers =
      content_type(app, 'application/octet-stream').call(request)[1]
    headers['Content-Type'].must_equal 'application/octet-stream'
  end

  it "not change Content-Type if it is already set" do
    app = lambda { |env| [200, {'Content-Type' => 'foo/bar'}, "Hello, World!"] }
    headers = content_type(app).call(request)[1]
    headers['Content-Type'].must_equal 'foo/bar'
  end

  it "detect Content-Type case insensitive" do
    app = lambda { |env| [200, {'CONTENT-Type' => 'foo/bar'}, "Hello, World!"] }
    headers = content_type(app).call(request)[1]
    headers.to_a.select { |k,v| k.downcase == "content-type" }.
      must_equal [["CONTENT-Type","foo/bar"]]
  end

  it "not set Content-Type on 304 responses" do
    app = lambda { |env| [304, {}, []] }
    response = content_type(app, "text/html").call(request)
    response[1]['Content-Type'].must_equal nil
  end
end

Version data entries

13 entries across 13 versions & 5 rubygems

Version Path
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/rack-2.0.1/test/spec_content_type.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/rack-2.0.1/test/spec_content_type.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/rack-2.0.1/test/spec_content_type.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/rack-2.0.1/test/spec_content_type.rb
autocompl-0.1.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/rack-2.0.1/test/spec_content_type.rb
autocompl-0.1.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/rack-2.0.1/test/spec_content_type.rb
autocompl-0.1.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/rack-2.0.1/test/spec_content_type.rb
autocompl-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/rack-2.0.1/test/spec_content_type.rb
abaci-0.3.0 vendor/bundle/gems/rack-2.0.1/test/spec_content_type.rb
second_step-0.1.2 secondstep-notify-1.0.0-osx/lib/ruby/lib/ruby/gems/2.2.0/gems/rack-2.0.1/test/spec_content_type.rb
rack-2.0.1 test/spec_content_type.rb
rack-2.0.0.rc1 test/spec_content_type.rb
rack-2.0.0.alpha test/spec_content_type.rb