Sha256: 1b776c97276e1fc4bcd03812fc3ed3ab96094ac1e5db52cb6f2bc5cdf180875f

Contents?: true

Size: 1.56 KB

Versions: 31

Compression:

Stored size: 1.56 KB

Contents

require 'test/spec'

require 'rack/session/cookie'
require 'rack/mock'
require 'rack/response'

context "Rack::Session::Cookie" do
  incrementor = lambda { |env|
    env["rack.session"]["counter"] ||= 0
    env["rack.session"]["counter"] += 1
    Rack::Response.new(env["rack.session"].inspect).to_a
  }

  specify "creates a new cookie" do
    res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor)).get("/")
    res["Set-Cookie"].should.match("rack.session=")
    res.body.should.equal '{"counter"=>1}'
  end

  specify "loads from a cookie" do
    res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor)).get("/")
    cookie = res["Set-Cookie"]
    res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor)).
      get("/", "HTTP_COOKIE" => cookie)
    res.body.should.equal '{"counter"=>2}'
    cookie = res["Set-Cookie"]
    res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor)).
      get("/", "HTTP_COOKIE" => cookie)
    res.body.should.equal '{"counter"=>3}'
  end

  specify "survives broken cookies" do
    res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor)).
      get("/", "HTTP_COOKIE" => "rack.session=blarghfasel")
    res.body.should.equal '{"counter"=>1}'
  end

  bigcookie = lambda { |env|
    env["rack.session"]["cookie"] = "big" * 3000
    Rack::Response.new(env["rack.session"].inspect).to_a
  }

  specify "barks on too big cookies" do
    lambda {
      Rack::MockRequest.new(Rack::Session::Cookie.new(bigcookie)).
        get("/", :fatal => true)
    }.should.raise(Rack::MockRequest::FatalWarning)
  end
end

Version data entries

31 entries across 31 versions & 7 rubygems

Version Path
3mix-castronaut-0.5.0.2 vendor/rack/test/spec_rack_session_cookie.rb
masover-castronaut-0.4.4.4 vendor/rack/test/spec_rack_session_cookie.rb
masover-castronaut-0.4.4.5 vendor/rack/test/spec_rack_session_cookie.rb
masover-castronaut-0.5.0.1 vendor/rack/test/spec_rack_session_cookie.rb
relevance-castronaut-0.2.0 vendor/rack/test/spec_rack_session_cookie.rb
relevance-castronaut-0.2.5 vendor/rack/test/spec_rack_session_cookie.rb
relevance-castronaut-0.3.0 vendor/rack/test/spec_rack_session_cookie.rb
relevance-castronaut-0.3.5 vendor/rack/test/spec_rack_session_cookie.rb
relevance-castronaut-0.3.6 vendor/rack/test/spec_rack_session_cookie.rb
relevance-castronaut-0.4.1 vendor/rack/test/spec_rack_session_cookie.rb
relevance-castronaut-0.4.2 vendor/rack/test/spec_rack_session_cookie.rb
relevance-castronaut-0.4.3 vendor/rack/test/spec_rack_session_cookie.rb
relevance-castronaut-0.4.4 vendor/rack/test/spec_rack_session_cookie.rb
relevance-castronaut-0.4.5 vendor/rack/test/spec_rack_session_cookie.rb
relevance-castronaut-0.4.6 vendor/rack/test/spec_rack_session_cookie.rb
relevance-castronaut-0.5.0 vendor/rack/test/spec_rack_session_cookie.rb
relevance-castronaut-0.5.1 vendor/rack/test/spec_rack_session_cookie.rb
relevance-castronaut-0.5.2 vendor/rack/test/spec_rack_session_cookie.rb
relevance-castronaut-0.5.3 vendor/rack/test/spec_rack_session_cookie.rb
relevance-castronaut-0.5.4 vendor/rack/test/spec_rack_session_cookie.rb