Sha256: 658b58289ee5cddc09c822af95fb15226a6b709379eb787fbed9e13d25c247be

Contents?: true

Size: 1.12 KB

Versions: 9

Compression:

Stored size: 1.12 KB

Contents

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

Version data entries

9 entries across 9 versions & 1 rubygems

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