From 9702636a08e50e9fed9bf76ad620a6a0a109009e Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 19 Feb 2009 21:21:34 -0600 Subject: Lazy evaluate ActionController session store middleware class to pickup custom plugin session stores [#2001 state:resolved] --- actionpack/lib/action_controller/middleware_stack.rb | 6 +++++- actionpack/lib/action_controller/middlewares.rb | 13 ++----------- actionpack/test/controller/middleware_stack_test.rb | 7 +++++++ 3 files changed, 14 insertions(+), 12 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/middleware_stack.rb b/actionpack/lib/action_controller/middleware_stack.rb index dbc2fda41e..ee0ae48ac0 100644 --- a/actionpack/lib/action_controller/middleware_stack.rb +++ b/actionpack/lib/action_controller/middleware_stack.rb @@ -27,7 +27,9 @@ module ActionController end def klass - if @klass.is_a?(Class) + if @klass.respond_to?(:call) + @klass.call + elsif @klass.is_a?(Class) @klass else @klass.to_s.constantize @@ -37,6 +39,8 @@ module ActionController end def active? + return false unless klass + if @conditional.respond_to?(:call) @conditional.call else diff --git a/actionpack/lib/action_controller/middlewares.rb b/actionpack/lib/action_controller/middlewares.rb index 8ea1b5c7ce..fd70eca1b1 100644 --- a/actionpack/lib/action_controller/middlewares.rb +++ b/actionpack/lib/action_controller/middlewares.rb @@ -4,17 +4,8 @@ use "Rack::Lock", :if => lambda { use "ActionController::Failsafe" -["ActionController::Session::CookieStore", - "ActionController::Session::MemCacheStore", - "ActiveRecord::SessionStore"].each do |store| - use(store, ActionController::Base.session_options, - :if => lambda { - if session_store = ActionController::Base.session_store - session_store.name == store - end - } - ) -end +use lambda { ActionController::Base.session_store }, + ActionController::Base.session_options use "ActionController::RewindableInput" use "ActionController::ParamsParser" diff --git a/actionpack/test/controller/middleware_stack_test.rb b/actionpack/test/controller/middleware_stack_test.rb index 2a141697da..612a710fa7 100644 --- a/actionpack/test/controller/middleware_stack_test.rb +++ b/actionpack/test/controller/middleware_stack_test.rb @@ -73,4 +73,11 @@ class MiddlewareStackTest < ActiveSupport::TestCase end end end + + test "lazy evaluates middleware class" do + assert_difference "@stack.size" do + @stack.use lambda { BazMiddleware } + end + assert_equal BazMiddleware, @stack.last.klass + end end -- cgit v1.2.3