Skip to content

Commit

Permalink
Fix brittle Time.now mock
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Mar 16, 2009
1 parent 39ff550 commit 367049c
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions actionpack/test/controller/session/cookie_store_test.rb
Expand Up @@ -199,29 +199,17 @@ def test_session_store_with_expire_after

with_test_route_set do
# First request accesses the session
time = Time.local(2008, 4, 24)
Time.stubs(:now).returns(time)
expected_expiry = (time + 5.hours).gmtime.strftime("%a, %d-%b-%Y %H:%M:%S GMT")

cookies[SessionKey] = SignedBar

get '/set_session_value'
assert_response :success
cookie = headers['Set-Cookie']

cookie_body = response.body
assert_equal "_myapp_session=#{cookie_body}; path=/; expires=#{expected_expiry}; HttpOnly",
headers['Set-Cookie']

# Second request does not access the session
time = Time.local(2008, 4, 25)
Time.stubs(:now).returns(time)
expected_expiry = (time + 5.hours).gmtime.strftime("%a, %d-%b-%Y %H:%M:%S GMT")

# Second request does not access the session so the
# expires header should not be changed
get '/no_session_access'
assert_response :success

assert_equal "_myapp_session=#{cookie_body}; path=/; expires=#{expected_expiry}; HttpOnly",
headers['Set-Cookie']
assert_equal cookie, headers['Set-Cookie']
end
end

Expand Down

0 comments on commit 367049c

Please sign in to comment.