Skip to content
This repository
Browse code

respect :expire_after option

- it was broken after
[commit](e0eb8e9)
- there's also
[issue](https://rails.lighthouseapp.com/projects/8994/tickets/6634-railsrack-inconsistency-about-expires_afterexpires-cookie-option)

- also: maybe it worth making Rack understand :expire_after as we
duplicate same logic in [cookie_store](https://github.com/gmarik/rails/blob/v2.3.11/actionpack/lib/action_controller/session/cookie_store.rb#L114)

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
commit b0be721dd95cdeead6b94447c1454cd7edabfa7a 1 parent 6c42c14
authored April 04, 2011 josevalim committed April 14, 2011
1  actionpack/lib/action_controller/session/abstract_store.rb
@@ -196,6 +196,7 @@ def call(env)
196 196
 
197 197
           if (request_cookies.nil? || request_cookies[@key] != sid) || options[:expire_after]
198 198
             cookie = {:value => sid}
  199
+            cookie[:expires] = Time.now + options[:expire_after] if options[:expire_after]
199 200
             Rack::Utils.set_cookie_header!(response[1], @key, cookie.merge(options))
200 201
           end
201 202
         end
64  actionpack/test/controller/session/abstract_store_test.rb
... ...
@@ -0,0 +1,64 @@
  1
+require 'abstract_unit'
  2
+
  3
+# You need to start a memcached server inorder to run these tests
  4
+class AbstractStoreTest < ActionController::IntegrationTest
  5
+  SessionKey = '_myapp_session'
  6
+  DispatcherApp = ActionController::Dispatcher.new
  7
+
  8
+  class TestController < ActionController::Base
  9
+    def get_session
  10
+      session[:test] = 'test'
  11
+      head :ok
  12
+    end
  13
+  end
  14
+
  15
+  def test_expiry_after
  16
+    with_test_route_set(:expire_after => 5 * 60) do
  17
+      get 'get_session'
  18
+      assert_response :success
  19
+      assert_match /expires=\S+/, headers['Set-Cookie']
  20
+    end
  21
+  end
  22
+
  23
+protected
  24
+
  25
+  def with_test_route_set(options = {})
  26
+    with_routing do |set|
  27
+      set.draw do |map|
  28
+        map.with_options :controller => "abstract_store_test/test" do |c|
  29
+          c.connect "/:action"
  30
+        end
  31
+      end
  32
+
  33
+      options = { :key => SessionKey, :secret => 'SessionSecret' }.merge!(options)
  34
+      @integration_session = open_session(TestStore.new(DispatcherApp, options))
  35
+
  36
+      yield
  37
+    end
  38
+  end
  39
+
  40
+  class TestStore < ActionController::Session::AbstractStore
  41
+    def initialize(app, options = {})
  42
+      super
  43
+      @_store = Hash.new({})
  44
+    end
  45
+
  46
+  private
  47
+
  48
+    def get_session(env, sid)
  49
+      sid ||= generate_sid
  50
+      session = @_store[sid]
  51
+      [sid, session]
  52
+    end
  53
+
  54
+    def set_session(env, sid, session_data)
  55
+      @_store[sid] = session_data
  56
+    end
  57
+
  58
+    def destroy(env)
  59
+      @_store.delete(sid)
  60
+    end
  61
+  end
  62
+
  63
+end
  64
+

0 notes on commit b0be721

Please sign in to comment.
Something went wrong with that request. Please try again.