public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Added session(:on) to turn session management back on in a controller subclass 
if the superclass turned it off (Peter Jones) [#136 state:resolved]
dhh (author)
Sun May 11 11:18:49 -0700 2008
commit  c43623c48b977d05413d86867651bfc3762b745a
tree    4ef380d032f57fdff2e9567fcc7b76db96249a6e
parent  8857994f92293a78df9addbc0998ef02fca82fae
...
69
70
71
 
 
 
 
72
73
74
75
76
 
77
78
79
...
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
0
@@ -69,11 +69,16 @@ module ActionController #:nodoc:
0
       #   session :off, 
0
       #     :if => Proc.new { |req| !(req.format.html? || req.format.js?) }
0
       #
0
+      #   # turn the session back on, useful when it was turned off in the
0
+      #   # application controller, and you need it on in another controller
0
+      #   session :on
0
+      #
0
       # All session options described for ActionController::Base.process_cgi
0
       # are valid arguments.
0
       def session(*args)
0
         options = args.extract_options!
0
 
0
+        options[:disabled] = false if args.delete(:on)
0
         options[:disabled] = true if !args.empty?
0
         options[:only] = [*options[:only]].map { |o| o.to_s } if options[:only]
0
         options[:except] = [*options[:except]].map { |o| o.to_s } if options[:except]
...
13
14
15
 
 
 
 
 
 
 
 
 
 
 
 
 
16
17
18
...
100
101
102
 
 
 
 
 
 
 
 
 
103
104
105
...
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
...
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
0
@@ -13,6 +13,19 @@ class SessionManagementTest < Test::Unit::TestCase
0
     end
0
   end
0
 
0
+  class SessionOffOnController < ActionController::Base
0
+    session :off
0
+    session :on, :only => :tell
0
+
0
+    def show
0
+      render :text => "done"
0
+    end
0
+
0
+    def tell
0
+      render :text => "done"
0
+    end
0
+  end
0
+
0
   class TestController < ActionController::Base
0
     session :off, :only => :show
0
     session :session_secure => true, :except => :show
0
@@ -100,6 +113,15 @@ class SessionManagementTest < Test::Unit::TestCase
0
     assert_equal false, @request.session_options
0
   end
0
 
0
+  def test_session_off_then_on_globally
0
+    @controller = SessionOffOnController.new
0
+    get :show
0
+    assert_equal false, @request.session_options
0
+    get :tell
0
+    assert_instance_of Hash, @request.session_options
0
+    assert_equal false, @request.session_options[:disabled]
0
+  end
0
+  
0
   def test_session_off_conditionally
0
     @controller = TestController.new
0
     get :show

Comments