Permalink
Browse files

Lazy evaluate ActionController session store middleware class to pick…

…up custom plugin session stores [#2001 state:resolved]
  • Loading branch information...
1 parent 3668a64 commit 9702636a08e50e9fed9bf76ad620a6a0a109009e @josh josh committed Feb 20, 2009
@@ -27,7 +27,9 @@ def initialize(klass, *args, &block)
end
def klass
- if @klass.is_a?(Class)
+ if @klass.respond_to?(:call)
+ @klass.call
@jaswope

jaswope Apr 7, 2010

Why was this conditional added? This causes problems when you try to use Rack middleware that runs as a singleton (like Sinatra). I can't find the reason in the lighthouse ticket.

+ elsif @klass.is_a?(Class)
@klass
else
@klass.to_s.constantize
@@ -37,6 +39,8 @@ def klass
end
def active?
+ return false unless klass
+
if @conditional.respond_to?(:call)
@conditional.call
else
@@ -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"
@@ -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 9702636

Please sign in to comment.