Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Lazy evaluate ActionController session store middleware class to pick…

…up custom plugin session stores [#2001 state:resolved]
  • Loading branch information...
commit 9702636a08e50e9fed9bf76ad620a6a0a109009e 1 parent 3668a64
@josh josh authored
View
6 actionpack/lib/action_controller/middleware_stack.rb
@@ -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 added a note

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ 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
View
13 actionpack/lib/action_controller/middlewares.rb
@@ -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"
View
7 actionpack/test/controller/middleware_stack_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.