mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Added session(:on) to turn session management back on in a controller subclass if the superclass turned it off (Peter Jones) [#136 state:resolved]
This commit is contained in:
parent
8857994f92
commit
c43623c48b
2 changed files with 27 additions and 0 deletions
|
@ -69,11 +69,16 @@ module ActionController #:nodoc:
|
||||||
# session :off,
|
# session :off,
|
||||||
# :if => Proc.new { |req| !(req.format.html? || req.format.js?) }
|
# :if => Proc.new { |req| !(req.format.html? || req.format.js?) }
|
||||||
#
|
#
|
||||||
|
# # turn the session back on, useful when it was turned off in the
|
||||||
|
# # application controller, and you need it on in another controller
|
||||||
|
# session :on
|
||||||
|
#
|
||||||
# All session options described for ActionController::Base.process_cgi
|
# All session options described for ActionController::Base.process_cgi
|
||||||
# are valid arguments.
|
# are valid arguments.
|
||||||
def session(*args)
|
def session(*args)
|
||||||
options = args.extract_options!
|
options = args.extract_options!
|
||||||
|
|
||||||
|
options[:disabled] = false if args.delete(:on)
|
||||||
options[:disabled] = true if !args.empty?
|
options[:disabled] = true if !args.empty?
|
||||||
options[:only] = [*options[:only]].map { |o| o.to_s } if options[:only]
|
options[:only] = [*options[:only]].map { |o| o.to_s } if options[:only]
|
||||||
options[:except] = [*options[:except]].map { |o| o.to_s } if options[:except]
|
options[:except] = [*options[:except]].map { |o| o.to_s } if options[:except]
|
||||||
|
|
|
@ -13,6 +13,19 @@ class SessionManagementTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class SessionOffOnController < ActionController::Base
|
||||||
|
session :off
|
||||||
|
session :on, :only => :tell
|
||||||
|
|
||||||
|
def show
|
||||||
|
render :text => "done"
|
||||||
|
end
|
||||||
|
|
||||||
|
def tell
|
||||||
|
render :text => "done"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class TestController < ActionController::Base
|
class TestController < ActionController::Base
|
||||||
session :off, :only => :show
|
session :off, :only => :show
|
||||||
session :session_secure => true, :except => :show
|
session :session_secure => true, :except => :show
|
||||||
|
@ -100,6 +113,15 @@ class SessionManagementTest < Test::Unit::TestCase
|
||||||
assert_equal false, @request.session_options
|
assert_equal false, @request.session_options
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_session_off_then_on_globally
|
||||||
|
@controller = SessionOffOnController.new
|
||||||
|
get :show
|
||||||
|
assert_equal false, @request.session_options
|
||||||
|
get :tell
|
||||||
|
assert_instance_of Hash, @request.session_options
|
||||||
|
assert_equal false, @request.session_options[:disabled]
|
||||||
|
end
|
||||||
|
|
||||||
def test_session_off_conditionally
|
def test_session_off_conditionally
|
||||||
@controller = TestController.new
|
@controller = TestController.new
|
||||||
get :show
|
get :show
|
||||||
|
|
Loading…
Reference in a new issue