Skip to content

Commit

Permalink
Fix redis-rack spec
Browse files Browse the repository at this point in the history
  * Sessions with expiry won't have matching cookies, so use the session
    ID instead
  * When a session expires, the counter should reset to 1
  * Send the whole cookie in the request instead of just the
    session_match bit
  • Loading branch information
mhoran committed Jan 26, 2012
1 parent 80195be commit 6f1d622
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions redis-rack/test/rack/session/redis_test.rb
Expand Up @@ -92,22 +92,23 @@
res = Rack::MockRequest.new(pool).get('/')
res.body.must_include('"counter"=>1')
cookie = res["Set-Cookie"]
sid = cookie[session_match, 1]
res = Rack::MockRequest.new(pool).get('/', "HTTP_COOKIE" => cookie)
res["Set-Cookie"].must_equal(cookie)
res["Set-Cookie"][session_match, 1].must_equal(sid)
res.body.must_include('"counter"=>2')
puts 'Sleeping to expire session' if $DEBUG
sleep 4
res = Rack::MockRequest.new(pool).get('/', "HTTP_COOKIE" => cookie)
res["Set-Cookie"].wont_equal(cookie)
res.body.must_include('"counter"=>3')
res["Set-Cookie"][session_match, 1].wont_equal(sid)
res.body.must_include('"counter"=>1')
end

it "does not send the same session id if it did not change" do
pool = Rack::Session::Redis.new(incrementor)
req = Rack::MockRequest.new(pool)

res0 = req.get("/")
cookie = res0["Set-Cookie"][session_match]
cookie = res0["Set-Cookie"]
res0.body.must_equal('{"counter"=>1}')

res1 = req.get("/", "HTTP_COOKIE" => cookie)
Expand Down Expand Up @@ -275,4 +276,4 @@
session['counter'].must_be_nil
session['foo'].must_equal('bar')
end
end
end

0 comments on commit 6f1d622

Please sign in to comment.