public
Description: A Ruby web application framework
Homepage: http://www.mackframework.com
Clone URL: git://github.com/markbates/mack.git
Click here to lend your support to: mack and make a donation at www.pledgie.com !
Feature: Applications should be able to turn of sessions globally [#42 
state:resolved]
markbates (author)
Mon Jul 21 10:17:32 -0700 2008
commit  1a8e6e762ea28fe77123d52b4d9d42c39d7b9ae3
tree    587e65fea9ccf3915bace9a506fb32b7f70f99a6
parent  d7a4552e914cd3d370db297eab96fabf7ef7a50f
...
 
1
2
3
...
1
2
3
4
0
@@ -1,3 +1,4 @@
0
+* Sessions can now be turned off globally using the app_config.mack.use_sessions switch. [#42]
0
 * gem: application_configuration 1.5.1
0
 
0
 ===0.6.0.1
...
43
44
45
 
46
47
48
...
43
44
45
46
47
48
49
0
@@ -43,6 +43,7 @@ module Mack
0
 
0
     # Gives access to the session. See Mack::Session for more information.
0
     def session
0
+      raise Mack::Errors::NoSessionError.new if self.request.session.nil?
0
       self.request.session
0
     end
0
 
...
1
2
3
 
 
 
 
4
5
6
...
1
2
3
4
5
6
7
8
9
10
0
@@ -1,6 +1,10 @@
0
 module Mack
0
   module Errors # :nodoc:
0
     
0
+    # Raised when there is no session available and one is trying to be accessed.
0
+    class NoSessionError < StandardError
0
+    end
0
+    
0
     # Raised when someone calls render twice in one action
0
     # 
0
     # Example:
...
61
62
63
 
64
65
66
...
61
62
63
64
65
66
67
0
@@ -61,6 +61,7 @@ module Mack
0
         "mack::cache_classes" => true,
0
         "mack::use_lint" => true,
0
         "mack::show_exceptions" => true,
0
+        "mack::use_sessions" => true,
0
         "mack::session_id" => "_mack_session_id",
0
         "mack::rendering_systems" => [:action, :text, :partial, :public, :url, :xml],
0
         "mack::cookie_values" => {
...
82
83
84
85
 
86
87
88
...
115
116
117
118
119
120
121
122
123
124
125
126
 
 
 
127
 
 
 
 
 
 
 
 
128
129
130
131
 
132
133
 
 
 
 
134
135
136
...
82
83
84
 
85
86
87
88
...
115
116
117
 
 
 
 
 
 
 
 
 
118
119
120
121
122
123
124
125
126
127
128
129
130
 
131
 
132
133
 
134
135
136
137
138
139
140
0
@@ -82,7 +82,7 @@ module Mack
0
       p_time = e_time - s_time
0
       if app_config.log.detailed_requests
0
         msg = "\n\t[#{@request.request_method.upcase}] '#{@request.path_info}'\n"
0
-        msg << "\tSession ID: #{@request.session.id}\n"
0
+        msg << "\tSession ID: #{@request.session.id}\n" if app_config.mack.use_sessions
0
         msg << "\tParameters: #{@request.all_params}\n"
0
         msg << "\tCompleted in #{p_time} (#{(1 / p_time).round} reqs/sec) | #{@response.status} [#{@request.full_host}]"
0
       else
0
@@ -115,22 +115,26 @@ module Mack
0
     end
0
     
0
     def session
0
-      sess_id = self.cookies[app_config.mack.session_id]
0
-      unless sess_id
0
-        sess_id = create_new_session
0
-      else
0
-        sess = Cachetastic::Caches::MackSessionCache.get(sess_id)
0
-        if sess
0
-          self.request.session = sess
0
-        else
0
-          # we couldn't find it in the store, so we need to create it:
0
+      if app_config.mack.use_sessions
0
+        sess_id = self.cookies[app_config.mack.session_id]
0
+        unless sess_id
0
           sess_id = create_new_session
0
+        else
0
+          sess = Cachetastic::Caches::MackSessionCache.get(sess_id)
0
+          if sess
0
+            self.request.session = sess
0
+          else
0
+            # we couldn't find it in the store, so we need to create it:
0
+            sess_id = create_new_session
0
+          end
0
         end
0
-      end
0
 
0
-      yield
0
+        yield
0
       
0
-      Cachetastic::Caches::MackSessionCache.set(sess_id, self.request.session)
0
+        Cachetastic::Caches::MackSessionCache.set(sess_id, self.request.session)
0
+      else
0
+        yield
0
+      end
0
     end
0
     
0
     def create_new_session
...
14
15
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
18
...
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
0
@@ -14,4 +14,33 @@ describe Mack::Session do
0
     
0
   end
0
   
0
+  describe "app_config.mack.use_sessions" do
0
+    
0
+    class SessionSpecController
0
+      include Mack::Controller
0
+      
0
+      def index
0
+        session[:id] = params[:id] if session[:id].nil?
0
+        render(:text, "id: #{session[:id]}")
0
+      end
0
+      
0
+    end
0
+    
0
+    it "should be able to turn off sessions" do
0
+      temp_app_config("mack::use_sessions" => false) do
0
+        lambda{get "/session_spec/index"}.should raise_error(Mack::Errors::NoSessionError)
0
+      end
0
+    end
0
+    
0
+    it "should be able to turn on sessions (default)" do
0
+      get "/session_spec/index?id=1"
0
+      response.body.should match(/id: 1/)
0
+      get "/session_spec/index"
0
+      response.body.should match(/id: 1/)
0
+      get "/session_spec/index?id=2"
0
+      response.body.should match(/id: 1/)
0
+    end
0
+    
0
+  end
0
+  
0
 end
0
\ No newline at end of file

Comments