Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 30 lines (26 sloc) 1.213 kb
fbb2ae41 » candlerb
2009-03-05 Add Rack::ContentType middleware
1 require 'rack/mock'
2 require 'rack/content_type'
3
4 context "Rack::ContentType" do
5 specify "sets Content-Type to default text/html if none is set" do
6 app = lambda { |env| [200, {}, "Hello, World!"] }
7 status, headers, body = Rack::ContentType.new(app).call({})
8 headers['Content-Type'].should.equal 'text/html'
9 end
10
11 specify "sets Content-Type to chosen default if none is set" do
12 app = lambda { |env| [200, {}, "Hello, World!"] }
13 status, headers, body =
14 Rack::ContentType.new(app, 'application/octet-stream').call({})
15 headers['Content-Type'].should.equal 'application/octet-stream'
16 end
17
18 specify "does not change Content-Type if it is already set" do
19 app = lambda { |env| [200, {'Content-Type' => 'foo/bar'}, "Hello, World!"] }
20 status, headers, body = Rack::ContentType.new(app).call({})
21 headers['Content-Type'].should.equal 'foo/bar'
22 end
23
24 specify "case insensitive detection of Content-Type" do
25 app = lambda { |env| [200, {'CONTENT-Type' => 'foo/bar'}, "Hello, World!"] }
26 status, headers, body = Rack::ContentType.new(app).call({})
27 headers.to_a.select { |k,v| k.downcase == "content-type" }.
28 should.equal [["CONTENT-Type","foo/bar"]]
29 end
30 end
Something went wrong with that request. Please try again.