diff options
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_controller/middleware_stack.rb | 6 | ||||
-rw-r--r-- | actionpack/lib/action_controller/middlewares.rb | 13 | ||||
-rw-r--r-- | actionpack/test/controller/middleware_stack_test.rb | 7 |
3 files changed, 14 insertions, 12 deletions
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 |