Sha256: 369be11ff128c5f87d2611aa751b9aa0c130af70375c78a20f1b67a8b4eba12a

Contents?: true

Size: 1.47 KB

Versions: 167

Compression:

Stored size: 1.47 KB

Contents

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
  
  should "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'].should.equal 'text/html'
  end

  should "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'].should.equal 'application/octet-stream'
  end

  should "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'].should.equal 'foo/bar'
  end

  should "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" }.
      should.equal [["CONTENT-Type","foo/bar"]]
  end

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

Version data entries

167 entries across 145 versions & 41 rubygems

Version Path
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_content_type.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_content_type.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_content_type.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_content_type.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_content_type.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_content_type.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_content_type.rb
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_content_type.rb
logstash-output-scalyr-0.1.21.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_content_type.rb
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_content_type.rb
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_content_type.rb
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_content_type.rb
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_content_type.rb
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_content_type.rb
logstash-output-scalyr-0.1.15.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_content_type.rb
logstash-output-scalyr-0.1.14.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_content_type.rb
logstash-output-scalyr-0.1.13 vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_content_type.rb
logstash-output-scalyr-0.1.12 vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_content_type.rb
logstash-output-scalyr-0.1.11.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_content_type.rb
logstash-output-scalyr-0.1.10.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_content_type.rb