Sha256: ac44446a470363e785430354c2a70980af15e428360a11c26e1d640f553176bf

Contents?: true

Size: 1.15 KB

Versions: 9

Compression:

Stored size: 1.15 KB

Contents

require 'rack/content_type'

describe Rack::ContentType do
  should "set Content-Type to default text/html if none is set" do
    app = lambda { |env| [200, {}, "Hello, World!"] }
    status, headers, body = Rack::ContentType.new(app).call({})
    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!"] }
    status, headers, body =
      Rack::ContentType.new(app, 'application/octet-stream').call({})
    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!"] }
    status, headers, body = Rack::ContentType.new(app).call({})
    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!"] }
    status, headers, body = Rack::ContentType.new(app).call({})
    headers.to_a.select { |k,v| k.downcase == "content-type" }.
      should.equal [["CONTENT-Type","foo/bar"]]
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rack-1.2.8 test/spec_content_type.rb
rack-1.2.7 test/spec_content_type.rb
rack-1.2.6 test/spec_content_type.rb
rack-1.2.5 test/spec_content_type.rb
rack-1.2.4 test/spec_content_type.rb
rack-1.2.3 test/spec_content_type.rb
rack-1.2.2 test/spec_content_type.rb
rack-1.2.1 test/spec_content_type.rb
rack-1.2.0 spec/spec_content_type.rb