diff options
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_controller/middleware_stack.rb | 10 | ||||
-rw-r--r-- | actionpack/lib/action_controller/middlewares.rb | 2 | ||||
-rw-r--r-- | actionpack/test/controller/middleware_stack_test.rb | 7 |
3 files changed, 16 insertions, 3 deletions
diff --git a/actionpack/lib/action_controller/middleware_stack.rb b/actionpack/lib/action_controller/middleware_stack.rb index ee0ae48ac0..b739a6d72d 100644 --- a/actionpack/lib/action_controller/middleware_stack.rb +++ b/actionpack/lib/action_controller/middleware_stack.rb @@ -67,11 +67,17 @@ module ActionController def build(app) if block - klass.new(app, *args, &block) + klass.new(app, *build_args, &block) else - klass.new(app, *args) + klass.new(app, *build_args) end end + + private + + def build_args + Array(args).map { |arg| arg.respond_to?(:call) ? arg.call : arg } + end end def initialize(*args, &block) diff --git a/actionpack/lib/action_controller/middlewares.rb b/actionpack/lib/action_controller/middlewares.rb index fd70eca1b1..371cf6d8f7 100644 --- a/actionpack/lib/action_controller/middlewares.rb +++ b/actionpack/lib/action_controller/middlewares.rb @@ -5,7 +5,7 @@ use "Rack::Lock", :if => lambda { use "ActionController::Failsafe" use lambda { ActionController::Base.session_store }, - ActionController::Base.session_options + lambda { 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 612a710fa7..918231013a 100644 --- a/actionpack/test/controller/middleware_stack_test.rb +++ b/actionpack/test/controller/middleware_stack_test.rb @@ -80,4 +80,11 @@ class MiddlewareStackTest < ActiveSupport::TestCase end assert_equal BazMiddleware, @stack.last.klass end + + test "lazy evaluates middleware arguments" do + assert_difference "@stack.size" do + @stack.use BazMiddleware, lambda { :foo } + end + assert_equal [:foo], @stack.last.send(:build_args) + end end |