session_off 0.4 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -186,7 +186,7 @@
186
186
  same "printed page" as the copyright notice for easier
187
187
  identification within third-party archives.
188
188
 
189
- Copyright (c) 2011 Karol Bucek
189
+ Copyright (c) 2011-2013 Karol Bucek
190
190
 
191
191
  Licensed under the Apache License, Version 2.0 (the "License");
192
192
  you may not use this file except in compliance with the License.
data/README.md CHANGED
@@ -6,46 +6,51 @@ where not (that) lazy loaded and one could have turned them off declaratively.
6
6
 
7
7
  I really liked this explicit approach and sure started missing it ever since it
8
8
  got redesigned. Now in theory it sounds great that if you do not touch the session
9
- it won't be loaded, but in practice enforcing your code to not invoke the session
10
- method (and thus not send a session cookie) for a (session-less) mobile client
9
+ it won't be loaded, but in practice enforcing your code to not invoke the session
10
+ method (and thus not send a session cookie) for a (session-less) mobile client
11
11
  while sharing the same code for "normal" (session-aware) clients, is just *hard*.
12
- you need to come up with a session state management and even so it's non-trivial
12
+ you need to come up with a session state management and even so it's non-trivial
13
13
  to track down "bugs" where you access the session while not really wanting to.
14
14
 
15
15
  How about we bring the love back and allow (once again) for a session to be off :
16
16
 
17
- session :off # turn session off for all actions
18
- session :off, :only => :bar # only for :bar action
19
- session :off, :except => :bar # except for :bar action
20
- session :only => :foo, # on for :foo when doing HTTPS
21
- :session_secure => true
22
- session :off, :only => :foo, # off for :foo, if :bar parameter present
23
- :if => Proc.new { |req| req.params[:bar].present? }
17
+ ```ruby
18
+ session :off # turn session off for all actions
19
+ session :off, :only => :bar # only for :bar action
20
+ session :off, :except => :bar # except for :bar action
21
+ session :only => :foo, # on for :foo when doing HTTPS
22
+ :session_secure => true
23
+ session :off, :only => :foo, # off for :foo, if :bar parameter present
24
+ :if => Proc.new { |req| req.params[:bar].present? }
25
+ ```
24
26
 
25
27
  **NOTE:** Keep in mind that after installing the plugin `session` might be nil !
26
28
  But only while using the `session` (instance) method in controllers, it does
27
29
  leave the `request.session` as is. Accessing the `request.session` directly will
28
- work (and load the session) no matter if the session is off. This is intentional
29
- as the goal of the plugin is to provide session management for controller code
30
+ work (and load the session) no matter if the session is off. This is intentional
31
+ as the goal of the plugin is to provide session management for controller code
30
32
  and not the whole middleware stack.
31
- I also highly discourage against using `session` inside model classes, as it is a
32
- lack of good desing, after all session's just an abstracted request "extension".
33
+ I also highly discourage against using `session` inside model classes, as it is a
34
+ lack of good design, after all session's just an abstracted request "extension".
33
35
 
34
36
  If in a need to check for a "disabled" session state from a request use :
35
37
 
36
- request.session_options[:disabled]
38
+ ```ruby
39
+ request.session_options[:disabled]
40
+ ```
37
41
 
38
42
  If unhappy with what happens while the session is turned off for an action :
39
43
 
40
- class ApplicationController < ActionController::Base
44
+ ```ruby
45
+ class ApplicationController < ActionController::Base
41
46
 
42
- def disable_session
43
- super # sets @_session = false (disabled)
44
- send_mama_a_kiss # or whatever you want !
45
- end
46
-
47
- end
47
+ def disable_session
48
+ super # sets @_session = false (disabled)
49
+ send_mama_a_kiss # or whatever you want !
50
+ end
48
51
 
52
+ end
53
+ ```
49
54
 
50
55
  Install
51
56
  =======
@@ -56,27 +61,29 @@ or as a plain-old rails plugin :
56
61
 
57
62
  script/plugin install git://github.com/kares/session_off.git
58
63
 
59
- Gem has been tested and should work with Rails **3.x** as well as **2.3**.
64
+ Gem has been tested and should work with Rails **4.x/3.x** as well as **2.3**.
60
65
 
61
66
  Example
62
67
  =======
63
68
 
64
69
  or how to be nice to robots :
65
70
 
66
- class RobotsController < ApplicationController
71
+ ```ruby
72
+ class RobotsController < ApplicationController
67
73
 
68
- # http://gurge.com/blog/2007/01/08/turn-off-rails-sessions-for-robots/
69
- ROBOTS = /\b(Baidu|Gigabot|Googlebot|libwww-perl|lwp-trivial|msnbot|SiteUptime|Slurp|WordPress|ZIBB|ZyBorg)\b/i
74
+ # http://gurge.com/blog/2007/01/08/turn-off-rails-sessions-for-robots/
75
+ ROBOTS = /\b(Baidu|Gigabot|Googlebot|libwww-perl|lwp-trivial|msnbot|SiteUptime|Slurp|WordPress|ZIBB|ZyBorg)\b/i
70
76
 
71
- # turn off sessions if this is a request from a robot
72
- session :off, :if => proc { |request| request.user_agent =~ ROBOTS }
73
-
74
- def greetings
75
- if session
76
- render :text => "SHALL WE PLAY A GAME ?"
77
- else
78
- render :text => "F*ck OFF, Stupid BOT !"
79
- end
80
- end
77
+ # turn off sessions if this is a request from a robot
78
+ session :off, :if => proc { |request| request.user_agent =~ ROBOTS }
81
79
 
80
+ def greetings
81
+ if session
82
+ render :text => "SHALL WE PLAY A GAME ?"
83
+ else
84
+ render :text => "F*ck OFF, Stupid BOT !"
82
85
  end
86
+ end
87
+
88
+ end
89
+ ```
data/Rakefile CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'rake'
2
2
  require 'rake/testtask'
3
- require 'rake/rdoctask'
4
3
 
5
4
  desc 'Default: run unit tests.'
6
5
  task :default => :test
@@ -11,12 +10,3 @@ Rake::TestTask.new(:test) do |t|
11
10
  t.pattern = 'test/*_test.rb'
12
11
  t.verbose = true
13
12
  end
14
-
15
- desc 'Generate documentation for the session_off plugin.'
16
- Rake::RDocTask.new(:rdoc) do |rdoc|
17
- rdoc.rdoc_dir = 'rdoc'
18
- rdoc.title = 'SessionOff'
19
- rdoc.options << '--line-numbers' << '--inline-source'
20
- rdoc.rdoc_files.include('README')
21
- rdoc.rdoc_files.include('lib/**/*.rb')
22
- end
@@ -2,14 +2,14 @@ module SessionOff
2
2
 
3
3
  def self.included(base)
4
4
  base.class_eval do
5
-
5
+
6
6
  extend ClassMethods
7
-
8
- if instance_methods(false).include?('session_enabled?')
7
+
8
+ if instance_methods(false).map(&:to_s).include?('session_enabled?')
9
9
  # remove the "deprecation" Rails 2.3 (can't override) :
10
10
  remove_method 'session_enabled?'
11
11
  end
12
- if instance_methods(false).include?('reset_session')
12
+ if instance_methods(false).map(&:to_s).include?('reset_session')
13
13
  # we'll have our own that respects session_enabled?
14
14
  # Rails 2.3 has this method in ActionController::Base
15
15
  remove_method 'reset_session'
@@ -17,17 +17,17 @@ module SessionOff
17
17
  # attr_internal on ActionController::Base for Rails 2.3.x
18
18
  # 3+ : `delegate :session, :to => "@_request"` from Metal
19
19
  clazz = self
20
- while clazz && ! clazz.instance_methods(false).include?('session')
20
+ while clazz && ! clazz.instance_methods(false).map(&:to_s).include?('session')
21
21
  clazz = clazz.superclass
22
22
  end
23
- clazz.send(:remove_method, :'session') if clazz
24
-
23
+ clazz.send(:remove_method, 'session') if clazz
24
+
25
25
  include InstanceMethods
26
26
 
27
27
  alias_method_chain(:process, :session_off)
28
28
  # yet another Rails 2.3 specific hook :
29
29
  alias_method_chain(:assign_shortcuts, :session_off) rescue NameError
30
-
30
+
31
31
  end
32
32
  end
33
33
 
@@ -36,7 +36,7 @@ module SessionOff
36
36
  def self.extended(base)
37
37
  return if base.respond_to?(:session_options_array)
38
38
  if base.respond_to?(:class_attribute)
39
- base.class_attribute :session_options_array,
39
+ base.class_attribute :session_options_array,
40
40
  :instance_reader => false, :instance_writer => false
41
41
  else
42
42
  base.class_eval do
@@ -49,7 +49,7 @@ module SessionOff
49
49
  end
50
50
  end
51
51
  end
52
-
52
+
53
53
  # Specify how sessions ought to be managed for a subset of the actions on
54
54
  # the controller. Like filters, you can specify <tt>:only</tt> and
55
55
  # <tt>:except</tt> clauses to restrict the subset, otherwise options
@@ -101,7 +101,7 @@ module SessionOff
101
101
  if options[:only] && options[:except]
102
102
  raise ArgumentError, "only one of either :only or :except are allowed"
103
103
  end
104
-
104
+
105
105
  if session_options_array
106
106
  self.session_options_array += [ options ]
107
107
  else
@@ -110,8 +110,8 @@ module SessionOff
110
110
  end
111
111
 
112
112
  def session_options_for(request, action)
113
- session_options =
114
- defined?(ActionController::Base.session_options) ?
113
+ session_options =
114
+ defined?(ActionController::Base.session_options) ?
115
115
  ActionController::Base.session_options.dup : {}
116
116
 
117
117
  if session_options_array.blank?
@@ -130,18 +130,18 @@ module SessionOff
130
130
  options.merge!(opts)
131
131
  end
132
132
  end
133
-
133
+
134
134
  options.delete(:only)
135
135
  options.delete(:except)
136
136
  options.delete(:if)
137
137
  options
138
138
  end
139
139
  end
140
-
140
+
141
141
  end
142
142
 
143
143
  module InstanceMethods
144
-
144
+
145
145
  def session_enabled?
146
146
  @_session != false
147
147
  end
@@ -161,13 +161,30 @@ module SessionOff
161
161
  @_session = false
162
162
  end
163
163
 
164
- if defined?(AbstractController::Base) # Rails 3+
164
+ if defined? AbstractController::Base # Rails 3+
165
+
166
+ if defined? ActionDispatch::Request::Session::Options # Rails 4.x
167
+
168
+ def process_with_session_off(action, *args)
169
+ session_options = self.class.session_options_for(request, action)
170
+ request_session_options = request.session_options
171
+ if request_session_options.is_a?(ActionDispatch::Request::Session::Options)
172
+ request_session_options = request_session_options.instance_variable_get(:@delegate)
173
+ end
174
+ request_session_options.merge! session_options
175
+ disable_session if session_options[:disabled]
176
+ process_without_session_off(action, *args)
177
+ end
178
+
179
+ else
180
+
181
+ def process_with_session_off(action, *args)
182
+ session_options = self.class.session_options_for(request, action)
183
+ request.session_options.merge! session_options
184
+ disable_session if session_options[:disabled]
185
+ process_without_session_off(action, *args)
186
+ end
165
187
 
166
- def process_with_session_off(action, *args)
167
- session_options = self.class.session_options_for(request, action)
168
- request.session_options.merge! session_options
169
- disable_session if session_options[:disabled]
170
- process_without_session_off(action, *args)
171
188
  end
172
189
 
173
190
  else # Rails 2.3.x
@@ -181,14 +198,14 @@ module SessionOff
181
198
  end
182
199
 
183
200
  private
184
-
185
- def assign_shortcuts_with_session_off(request, response)
186
- assign_shortcuts_without_session_off(request, response)
187
- disable_session if request.session_options[:disabled]
188
- end
201
+
202
+ def assign_shortcuts_with_session_off(request, response)
203
+ assign_shortcuts_without_session_off(request, response)
204
+ disable_session if request.session_options[:disabled]
205
+ end
189
206
 
190
207
  end
191
-
208
+
192
209
  end
193
210
 
194
211
  end
@@ -3,10 +3,8 @@ require File.expand_path('test_helper', File.dirname(__FILE__))
3
3
  # inspired by Rails 2.2.3's session_management_test !
4
4
  class SessionManagementTest < ActionController::TestCase # Test::Unit::TestCase
5
5
 
6
- def setup
7
- @request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new
8
- end
9
-
6
+ include TestSessionRequest if defined? TestSessionRequest
7
+
10
8
  class SessionOffController < ActionController::Base
11
9
  session :off
12
10
 
@@ -18,20 +16,20 @@ class SessionManagementTest < ActionController::TestCase # Test::Unit::TestCase
18
16
  render :text => "done"
19
17
  end
20
18
  end
21
-
19
+
22
20
  test 'session_off_globally for action' do
23
21
  @controller = SessionOffController.new
24
-
22
+
25
23
  get :show
26
24
  assert_no_session
27
25
  end
28
-
26
+
29
27
  test 'session_off_globally for another action' do
30
28
  @controller = SessionOffController.new
31
-
29
+
32
30
  get :tell
33
31
  assert_no_session
34
- end
32
+ end
35
33
 
36
34
  class SessionOffOnController < ActionController::Base
37
35
  session :off
@@ -45,21 +43,21 @@ class SessionManagementTest < ActionController::TestCase # Test::Unit::TestCase
45
43
  render :text => "done"
46
44
  end
47
45
  end
48
-
46
+
49
47
  test 'session_off_globally_then_on for non-matched action' do
50
48
  @controller = SessionOffOnController.new
51
-
49
+
52
50
  get :show
53
51
  assert_no_session
54
52
  end
55
53
 
56
54
  test 'session_off_globally_then_on for matched action' do
57
55
  @controller = SessionOffOnController.new
58
-
56
+
59
57
  get :tell
60
58
  assert_session
61
59
  assert_equal false, @request.session_options[:disabled]
62
- end
60
+ end
63
61
 
64
62
  class SpecializedController < SessionOffController
65
63
  session :disabled => false, :only => :something
@@ -72,21 +70,21 @@ class SessionManagementTest < ActionController::TestCase # Test::Unit::TestCase
72
70
  render :text => "done"
73
71
  end
74
72
  end
75
-
73
+
76
74
  test 'controller_specialization_overrides_settings 1' do
77
75
  @controller = SpecializedController.new
78
-
76
+
79
77
  get :something
80
78
  assert_session
81
79
  end
82
80
 
83
81
  test 'controller_specialization_overrides_settings 2' do
84
82
  @controller = SpecializedController.new
85
-
83
+
86
84
  get :another
87
85
  assert_no_session
88
86
  end
89
-
87
+
90
88
  class TestController < ActionController::Base
91
89
  session :off, :only => :show
92
90
  session :session_secure => true, :except => :show
@@ -105,43 +103,41 @@ class SessionManagementTest < ActionController::TestCase # Test::Unit::TestCase
105
103
  render :text => ">>>#{params[:ws]}<<<"
106
104
  end
107
105
  end
108
-
106
+
109
107
  test 'multiple session offs - off for (non-conditional) action' do
110
108
  @controller = TestController.new
111
-
109
+
112
110
  get :show
113
111
  assert_no_session
114
112
  end
115
113
 
116
114
  test 'multiple session offs - except (non-conditional) action' do
117
115
  @controller = TestController.new
118
-
116
+
119
117
  get :tell
120
118
  assert_session
121
119
  assert @request.session_options[:session_secure]
122
120
  end
123
-
121
+
124
122
  test 'multiple session offs - on if condition not met' do
125
123
  @controller = TestController.new
126
-
124
+
127
125
  get :conditional
128
126
  assert_session
129
127
  end
130
128
 
131
129
  test 'multiple session offs - off if condition met' do
132
130
  @controller = TestController.new
133
-
131
+
134
132
  get :conditional, :ws => "ws"
135
133
  assert_no_session
136
134
  end
137
-
135
+
138
136
  test 'session_is_not_enabled' do
139
137
  @controller = TestController.new
140
-
138
+
141
139
  get :show
142
- assert_nothing_raised do
143
- assert_equal false, @controller.session_enabled?
144
- end
140
+ assert_equal false, @controller.session_enabled?
145
141
  end
146
142
 
147
143
  test 'session_is_enabled' do
@@ -150,7 +146,7 @@ class SessionManagementTest < ActionController::TestCase # Test::Unit::TestCase
150
146
  get :tell
151
147
  assert @controller.session_enabled?
152
148
  end
153
-
149
+
154
150
  private
155
151
 
156
152
  def assert_session
@@ -2,6 +2,8 @@ require File.expand_path('test_helper', File.dirname(__FILE__))
2
2
 
3
3
  class SessionOffTest < ActionController::TestCase
4
4
 
5
+ include TestSessionRequest if defined? TestSessionRequest
6
+
5
7
  class TestController < ActionController::Base
6
8
 
7
9
  session :off, :secure => false, :except => [ :on ],
@@ -30,14 +32,14 @@ class SessionOffTest < ActionController::TestCase
30
32
  super
31
33
  @disable_session = true
32
34
  end
33
-
35
+
34
36
  end
35
37
 
36
38
  tests TestController
37
-
39
+
38
40
  setup :save_session_options
39
41
  teardown :restore_session_options
40
-
42
+
41
43
  test "session is on" do
42
44
  get :on
43
45
  assert session
@@ -60,7 +62,7 @@ class SessionOffTest < ActionController::TestCase
60
62
  request.expects(:reset_session).never
61
63
  get :reset
62
64
  end
63
-
65
+
64
66
  test "session is reset if it's on" do
65
67
  request.expects(:reset_session).once
66
68
  get :reset, :force_session => '1'
@@ -68,19 +70,22 @@ class SessionOffTest < ActionController::TestCase
68
70
 
69
71
  test "request session options are merged" do
70
72
  session_options = request.session_options.dup
71
- begin
72
- request.session_options[:bar] = 'foo'
73
- get :on
74
- assert request.session_options
75
- assert_equal 'foo', request.session_options[:bar]
76
- ensure
77
- request.session_options.clear
78
- request.session_options.merge!(session_options)
79
- end
73
+ request.session_options[:bar] = 'foo'
74
+ get :on
75
+ assert request.session_options
76
+ assert_equal 'foo', request.session_options[:bar]
80
77
  end
81
-
78
+
79
+ test "same session options class is kept" do
80
+ session_options_class = request.session_options.class
81
+ request.session_options[:bar] = 'foo'
82
+ get :on
83
+ assert request.session_options
84
+ assert_equal session_options_class, request.session_options.class
85
+ end
86
+
82
87
  if defined?(ActionController::Base.session_options)
83
-
88
+
84
89
  test "global session options are available" do
85
90
  session_options = ActionController::Base.session_options.dup
86
91
  begin
@@ -106,7 +111,7 @@ class SessionOffTest < ActionController::TestCase
106
111
  end
107
112
 
108
113
  end
109
-
114
+
110
115
  test "disable session is called when turning session off" do
111
116
  get :off
112
117
  assert_equal true, @controller.instance_variable_get(:@disable_session)
@@ -116,5 +121,5 @@ class SessionOffTest < ActionController::TestCase
116
121
  get :on
117
122
  assert_equal nil, @controller.instance_variable_get(:@disable_session)
118
123
  end
119
-
124
+
120
125
  end
@@ -1,32 +1,19 @@
1
1
  require 'rubygems'
2
+ require 'bundler/setup'
2
3
 
3
4
  require 'yaml'
4
5
  require 'stringio'
5
- require 'test/unit'
6
- require 'mocha'
7
-
8
- version =
9
- if ARGV.find { |opt| /RAILS_VERSION=([\d\.]+)/ =~ opt }
10
- $~[1]
11
- else
12
- ENV['RAILS_VERSION'] # rake test RAILS_VERSION=2.3.5
13
- end
14
6
 
15
- if version
16
- RAILS_VERSION = version
17
- gem 'activesupport', "= #{RAILS_VERSION}"
18
- gem 'activerecord', "= #{RAILS_VERSION}"
19
- gem 'actionpack', "= #{RAILS_VERSION}"
20
- gem 'actionmailer', "= #{RAILS_VERSION}"
21
- gem 'rails', "= #{RAILS_VERSION}"
22
- else
23
- gem 'activesupport'
24
- gem 'activerecord'
25
- gem 'actionpack'
26
- gem 'actionmailer'
27
- gem 'rails'
7
+ require 'minitest/autorun'
8
+ begin
9
+ require 'mocha/setup'
10
+ rescue LoadError
11
+ require 'mocha'
28
12
  end
29
13
 
14
+ # NOTE: stub-out test/unit (Rails 2.3/3.x requires some of it)
15
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '../test')
16
+
30
17
  require 'active_support'
31
18
  require 'active_support/test_case'
32
19
  require 'action_controller'
@@ -35,6 +22,8 @@ require 'action_controller/test_case'
35
22
  require 'rails/version'
36
23
  puts "emulating Rails.version = #{Rails::VERSION::STRING}"
37
24
 
25
+ require 'test/unit' if Rails::VERSION::MAJOR < 3
26
+
38
27
  require 'action_controller/integration' if Rails::VERSION::MAJOR < 3
39
28
  require 'action_controller/session_management' if Rails::VERSION::MAJOR < 3
40
29
  require 'action_dispatch' if Rails::VERSION::MAJOR >= 3
@@ -47,7 +36,8 @@ else
47
36
  end
48
37
 
49
38
  ActionController::Base.logger = nil
50
- ActionController::Routing::Routes.reload rescue nil
39
+ routing = ActionDispatch::Routing rescue ActionController::Routing
40
+ routing::Routes.reload rescue nil
51
41
 
52
42
  if Rails::VERSION::MAJOR >= 3
53
43
  require 'rails'
@@ -137,19 +127,28 @@ else # since Rails 3.0.0 :
137
127
  end
138
128
  end
139
129
 
130
+ SessionOff::Application.configure do
131
+ config.cache_classes = true
132
+ config.eager_load = true rescue nil
133
+ end
134
+
140
135
  # Initialize the rails application
141
136
  SessionOff::Application.initialize!
142
137
  SessionOff::Application.routes.draw do
143
- match '/:controller(/:action(/:id))'
138
+ begin
139
+ get "/:controller(/:action(/:id))" # 4.0
140
+ rescue
141
+ match '/:controller(/:action(/:id))'
142
+ end
144
143
  end
145
144
 
146
145
  end
147
146
 
148
147
  class ActionController::TestCase
149
-
148
+
150
149
  attr_reader :request, :response
151
150
  @@session_options = nil
152
-
151
+
153
152
  def save_session_options
154
153
  @@session_options = request.session_options.dup
155
154
  end
@@ -157,8 +156,10 @@ class ActionController::TestCase
157
156
  def restore_session_options
158
157
  request.session_options = @@session_options
159
158
  end
160
-
159
+
161
160
  end
162
161
 
163
162
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '../lib')
164
163
  require 'session_off'
164
+
165
+ require 'test_session_request'
@@ -0,0 +1,72 @@
1
+ require 'securerandom'
2
+
3
+ module ActionController
4
+
5
+ class TestSessionStore < Rack::Session::Abstract::ID
6
+
7
+ def initialize(app = nil)
8
+ super(app)
9
+ end
10
+
11
+ def get_session(env, sid)
12
+ ( @sessions ||= {} )[sid]
13
+ end
14
+
15
+ def set_session(env, sid, session, options)
16
+ ( @sessions ||= {} )[sid] = session
17
+ end
18
+
19
+ def destroy_session(env, sid, options)
20
+ ( @sessions ||= {} ).delete(sid)
21
+ end
22
+
23
+ public :load_session
24
+
25
+ end
26
+
27
+ class TestSessionRequest < TestRequest
28
+
29
+ def initialize(env = {})
30
+ super
31
+
32
+ # self.session = TestSession.new
33
+ # self.session_options = TestSession::DEFAULT_OPTIONS.merge(:id => SecureRandom.hex(16))
34
+
35
+ store = TestSessionStore.new
36
+ default_options =
37
+ TestSession::DEFAULT_OPTIONS rescue Rack::Session::Abstract::ID::DEFAULT_OPTIONS
38
+ default_options = default_options.merge(:id => SecureRandom.hex(16))
39
+
40
+ if defined? ActionDispatch::Request::Session # 4.x
41
+ session = ActionDispatch::Request::Session.create(store, env, default_options)
42
+ session_options = session.options
43
+ else
44
+ session = TestSession.new
45
+ session_options = default_options
46
+ end
47
+
48
+ self.session = session; self.session_options = session_options
49
+ end
50
+
51
+ end
52
+ end
53
+
54
+ module TestSessionRequest
55
+
56
+ def setup_controller_request_and_response
57
+ @request = ActionController::TestSessionRequest.new
58
+ @response = ActionController::TestResponse.new
59
+
60
+ if klass = self.class.controller_class
61
+ @controller ||= klass.new rescue nil
62
+ end
63
+
64
+ @request.env.delete('PATH_INFO')
65
+
66
+ if defined?(@controller) && @controller
67
+ @controller.request = @request
68
+ @controller.params = {}
69
+ end
70
+ end
71
+
72
+ end
metadata CHANGED
@@ -1,101 +1,108 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: session_off
3
- version: !ruby/object:Gem::Version
4
- hash: 3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 4
9
- version: "0.4"
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Karol Bucek
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2012-01-22 00:00:00 Z
18
- dependencies:
19
- - !ruby/object:Gem::Dependency
12
+ date: 2013-07-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
20
15
  name: actionpack
21
- prerelease: false
22
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
23
17
  none: false
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- hash: 5
28
- segments:
29
- - 2
30
- - 3
31
- version: "2.3"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '2.3'
32
22
  type: :runtime
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: mocha
36
23
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '2.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: minitest
32
+ requirement: !ruby/object:Gem::Requirement
38
33
  none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '4.5'
46
38
  type: :development
47
- version_requirements: *id002
48
- description: session :off, :only => :foo, :if => Proc.new { |req| req.params[:bar] }
49
- email:
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '4.5'
46
+ - !ruby/object:Gem::Dependency
47
+ name: mocha
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.13.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.13.0
62
+ description: session :off, :only => :foo, :if => Proc.new { |req| req.params[:bar]
63
+ }
64
+ email:
50
65
  - self@kares.org
51
66
  executables: []
52
-
53
67
  extensions: []
54
-
55
- extra_rdoc_files:
68
+ extra_rdoc_files:
56
69
  - README.md
57
- files:
70
+ files:
58
71
  - lib/session_off.rb
59
72
  - LICENSE
60
73
  - README.md
61
74
  - Rakefile
62
- - test/session_off_test.rb
63
- - test/session_management_test.rb
64
75
  - test/test_helper.rb
76
+ - test/session_management_test.rb
77
+ - test/session_off_test.rb
78
+ - test/test_session_request.rb
65
79
  homepage: http://github.com/kares/session_off
66
80
  licenses: []
67
-
68
81
  post_install_message:
69
82
  rdoc_options: []
70
-
71
- require_paths:
83
+ require_paths:
72
84
  - lib
73
- required_ruby_version: !ruby/object:Gem::Requirement
85
+ required_ruby_version: !ruby/object:Gem::Requirement
74
86
  none: false
75
- requirements:
76
- - - ">="
77
- - !ruby/object:Gem::Version
78
- hash: 3
79
- segments:
80
- - 0
81
- version: "0"
82
- required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
92
  none: false
84
- requirements:
85
- - - ">="
86
- - !ruby/object:Gem::Version
87
- hash: 3
88
- segments:
89
- - 0
90
- version: "0"
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
91
97
  requirements: []
92
-
93
- rubyforge_project: "[none]"
94
- rubygems_version: 1.8.15
98
+ rubyforge_project: ! '[none]'
99
+ rubygems_version: 1.8.25
95
100
  signing_key:
96
101
  specification_version: 3
97
- summary: declarative session :off from Rails 2.2 'backported'
98
- test_files:
99
- - test/session_off_test.rb
100
- - test/session_management_test.rb
102
+ summary: declarative session :off 'backported' from Rails 2.2
103
+ test_files:
101
104
  - test/test_helper.rb
105
+ - test/session_management_test.rb
106
+ - test/session_off_test.rb
107
+ - test/test_session_request.rb
108
+ has_rdoc: