Skip to content
This repository
Browse code

Added session(:on) to turn session management back on in a controller…

… subclass if the superclass turned it off (Peter Jones) [#136 state:resolved]
  • Loading branch information...
commit c43623c48b977d05413d86867651bfc3762b745a 1 parent 8857994
David Heinemeier Hansson authored May 11, 2008
5  actionpack/lib/action_controller/session_management.rb
@@ -69,11 +69,16 @@ def session_options
69 69
       #   session :off, 
70 70
       #     :if => Proc.new { |req| !(req.format.html? || req.format.js?) }
71 71
       #
  72
+      #   # turn the session back on, useful when it was turned off in the
  73
+      #   # application controller, and you need it on in another controller
  74
+      #   session :on
  75
+      #
72 76
       # All session options described for ActionController::Base.process_cgi
73 77
       # are valid arguments.
74 78
       def session(*args)
75 79
         options = args.extract_options!
76 80
 
  81
+        options[:disabled] = false if args.delete(:on)
77 82
         options[:disabled] = true if !args.empty?
78 83
         options[:only] = [*options[:only]].map { |o| o.to_s } if options[:only]
79 84
         options[:except] = [*options[:except]].map { |o| o.to_s } if options[:except]
22  actionpack/test/controller/session_management_test.rb
@@ -13,6 +13,19 @@ def tell
13 13
     end
14 14
   end
15 15
 
  16
+  class SessionOffOnController < ActionController::Base
  17
+    session :off
  18
+    session :on, :only => :tell
  19
+
  20
+    def show
  21
+      render :text => "done"
  22
+    end
  23
+
  24
+    def tell
  25
+      render :text => "done"
  26
+    end
  27
+  end
  28
+
16 29
   class TestController < ActionController::Base
17 30
     session :off, :only => :show
18 31
     session :session_secure => true, :except => :show
@@ -100,6 +113,15 @@ def test_session_off_globally
100 113
     assert_equal false, @request.session_options
101 114
   end
102 115
 
  116
+  def test_session_off_then_on_globally
  117
+    @controller = SessionOffOnController.new
  118
+    get :show
  119
+    assert_equal false, @request.session_options
  120
+    get :tell
  121
+    assert_instance_of Hash, @request.session_options
  122
+    assert_equal false, @request.session_options[:disabled]
  123
+  end
  124
+  
103 125
   def test_session_off_conditionally
104 126
     @controller = TestController.new
105 127
     get :show

0 notes on commit c43623c

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