2009-12-19 03:16:58 +01:00
|
|
|
require 'rack/content_type'
|
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
describe Rack::ContentType do
|
|
|
|
should "set Content-Type to default text/html if none is set" do
|
2009-12-19 03:16:58 +01:00
|
|
|
app = lambda { |env| [200, {}, "Hello, World!"] }
|
|
|
|
status, headers, body = Rack::ContentType.new(app).call({})
|
|
|
|
headers['Content-Type'].should.equal 'text/html'
|
|
|
|
end
|
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
should "set Content-Type to chosen default if none is set" do
|
2009-12-19 03:16:58 +01:00
|
|
|
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
|
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
should "not change Content-Type if it is already set" do
|
2009-12-19 03:16:58 +01:00
|
|
|
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
|
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
should "detect Content-Type case insensitive" do
|
2009-12-19 03:16:58 +01:00
|
|
|
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
|