Skip to content

Commit

Permalink
Don't default ttl to 0 in DalliStore since DalliClient needs to be ab…
Browse files Browse the repository at this point in the history
…le to override.
  • Loading branch information
Ben Lindsey committed Jan 30, 2011
1 parent ec8bc50 commit 57b9724
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/action_controller/session/dalli_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get_session(env, sid)

def set_session(env, sid, session_data)
options = env['rack.session.options']
expiry = options[:expire_after] || 0
expiry = options[:expire_after]
@pool.set(sid, session_data, expiry)
return true
rescue Dalli::DalliError
Expand Down
2 changes: 1 addition & 1 deletion lib/action_dispatch/middleware/session/dalli_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def get_session(env, sid)

def set_session(env, sid, session_data, options = nil)
options ||= env[ENV_SESSION_OPTIONS_KEY]
expiry = options[:expire_after] || 0
expiry = options[:expire_after]
@pool.set(sid, session_data, expiry)
sid
rescue Dalli::DalliError
Expand Down
31 changes: 28 additions & 3 deletions test/test_session_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,24 +182,49 @@ def test_prevents_session_fixation
assert_not_equal session_id, cookies['_session_id']
end
end

def test_expire_after
with_test_route_set(:expire_after => 1) do
get '/set_session_value'
assert_match /expires/, @response.headers['Set-Cookie']

sleep(1)

get '/get_session_value'
assert_equal 'foo: nil', response.body
end
end

def test_expires_in
with_test_route_set(:expires_in => 1) do
get '/set_session_value'
assert_no_match /expires/, @response.headers['Set-Cookie']

sleep(1)

get '/get_session_value'
assert_equal 'foo: nil', response.body
end
end
rescue LoadError, RuntimeError
$stderr.puts "Skipping TestSessionStore tests. Start memcached and try again."
end

private
def with_test_route_set
def with_test_route_set(options = {})
options = {:key => '_session_id'}.merge(options)
with_routing do |set|
set.draw do |map|
match ':action', :to => ::TestSessionStore::TestController
end

@app = self.class.build_app(set) do |middleware|
middleware.use ActionDispatch::Session::DalliStore, :key => '_session_id'
middleware.use ActionDispatch::Session::DalliStore, options
middleware.delete "ActionDispatch::ShowExceptions"
end

yield
end
end
end
end
end

0 comments on commit 57b9724

Please sign in to comment.