Skip to content
This repository

Here's the one line fix for expires_in #64

Merged
1 commit merged into from over 3 years ago

1 participant

Ben Lindsey
Ben Lindsey

The default ttl is 0 in DalliClient so there is no reason to set it in DalliStore. That way you can not set expires_after and set expires_on instead of you want a browser session cookie.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jan 30, 2011
Ben Lindsey Don't default ttl to 0 in DalliStore since DalliClient needs to be ab…
…le to override.
57b9724
This page is out of date. Refresh to see the latest.
2  lib/action_controller/session/dalli_store.rb
@@ -37,7 +37,7 @@ def get_session(env, sid)
37 37
38 38 def set_session(env, sid, session_data)
39 39 options = env['rack.session.options']
40   - expiry = options[:expire_after] || 0
  40 + expiry = options[:expire_after]
41 41 @pool.set(sid, session_data, expiry)
42 42 return true
43 43 rescue Dalli::DalliError
2  lib/action_dispatch/middleware/session/dalli_store.rb
@@ -45,7 +45,7 @@ def get_session(env, sid)
45 45
46 46 def set_session(env, sid, session_data, options = nil)
47 47 options ||= env[ENV_SESSION_OPTIONS_KEY]
48   - expiry = options[:expire_after] || 0
  48 + expiry = options[:expire_after]
49 49 @pool.set(sid, session_data, expiry)
50 50 sid
51 51 rescue Dalli::DalliError
31 test/test_session_store.rb
@@ -182,19 +182,44 @@ def test_prevents_session_fixation
182 182 assert_not_equal session_id, cookies['_session_id']
183 183 end
184 184 end
  185 +
  186 + def test_expire_after
  187 + with_test_route_set(:expire_after => 1) do
  188 + get '/set_session_value'
  189 + assert_match /expires/, @response.headers['Set-Cookie']
  190 +
  191 + sleep(1)
  192 +
  193 + get '/get_session_value'
  194 + assert_equal 'foo: nil', response.body
  195 + end
  196 + end
  197 +
  198 + def test_expires_in
  199 + with_test_route_set(:expires_in => 1) do
  200 + get '/set_session_value'
  201 + assert_no_match /expires/, @response.headers['Set-Cookie']
  202 +
  203 + sleep(1)
  204 +
  205 + get '/get_session_value'
  206 + assert_equal 'foo: nil', response.body
  207 + end
  208 + end
185 209 rescue LoadError, RuntimeError
186 210 $stderr.puts "Skipping TestSessionStore tests. Start memcached and try again."
187 211 end
188 212
189 213 private
190   - def with_test_route_set
  214 + def with_test_route_set(options = {})
  215 + options = {:key => '_session_id'}.merge(options)
191 216 with_routing do |set|
192 217 set.draw do |map|
193 218 match ':action', :to => ::TestSessionStore::TestController
194 219 end
195 220
196 221 @app = self.class.build_app(set) do |middleware|
197   - middleware.use ActionDispatch::Session::DalliStore, :key => '_session_id'
  222 + middleware.use ActionDispatch::Session::DalliStore, options
198 223 middleware.delete "ActionDispatch::ShowExceptions"
199 224 end
200 225
@@ -202,4 +227,4 @@ def with_test_route_set
202 227 end
203 228 end
204 229 end
205   -end
  230 +end

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.