instiki/vendor/plugins/rack/test/spec_conditionalget.rb
Jacques Distler 0d8f680d4f Updates
SVG-Edit -> 2.5final
Vendored Rack -> 1.2.1
2010-06-17 19:27:39 -05:00

40 lines
1.1 KiB
Ruby

require 'time'
require 'rack/conditionalget'
require 'rack/mock'
describe Rack::ConditionalGet do
should "set a 304 status and truncate body when If-Modified-Since hits" do
timestamp = Time.now.httpdate
app = Rack::ConditionalGet.new(lambda { |env|
[200, {'Last-Modified'=>timestamp}, ['TEST']] })
response = Rack::MockRequest.new(app).
get("/", 'HTTP_IF_MODIFIED_SINCE' => timestamp)
response.status.should.equal 304
response.body.should.be.empty
end
should "set a 304 status and truncate body when If-None-Match hits" do
app = Rack::ConditionalGet.new(lambda { |env|
[200, {'Etag'=>'1234'}, ['TEST']] })
response = Rack::MockRequest.new(app).
get("/", 'HTTP_IF_NONE_MATCH' => '1234')
response.status.should.equal 304
response.body.should.be.empty
end
should "not affect non-GET/HEAD requests" do
app = Rack::ConditionalGet.new(lambda { |env|
[200, {'Etag'=>'1234'}, ['TEST']] })
response = Rack::MockRequest.new(app).
post("/", 'HTTP_IF_NONE_MATCH' => '1234')
response.status.should.equal 200
response.body.should.equal 'TEST'
end
end