Skip to content

Commit

Permalink
Lazy evaluate ActionController session store middleware class to pick…
Browse files Browse the repository at this point in the history
…up custom plugin session stores [rails#2001 state:resolved]
  • Loading branch information
josh authored and alloy committed Feb 20, 2009
1 parent 61a9d1d commit 140f0ab
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
6 changes: 5 additions & 1 deletion actionpack/lib/action_controller/middleware_stack.rb
Expand Up @@ -27,7 +27,9 @@ def initialize(klass, *args, &block)
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
Expand All @@ -37,6 +39,8 @@ def klass
end

def active?
return false unless klass

if @conditional.respond_to?(:call)
@conditional.call
else
Expand Down
13 changes: 2 additions & 11 deletions actionpack/lib/action_controller/middlewares.rb
Expand Up @@ -4,17 +4,8 @@

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"
Expand Down
7 changes: 7 additions & 0 deletions actionpack/test/controller/middleware_stack_test.rb
Expand Up @@ -73,4 +73,11 @@ def setup
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

0 comments on commit 140f0ab

Please sign in to comment.