diff options
author | Collin Miller <collintmiller@gmail.com> | 2010-09-12 05:30:21 +0800 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-09-12 07:35:54 +0800 |
commit | 96650f704a7a36097d634972484a305a639143c7 (patch) | |
tree | bcb08700c195984bb0e7a882bf42da8dcbc9588d /actionpack/test/controller | |
parent | 0aa66f04e4b4698718023cacb18612e04a4c5eb1 (diff) | |
download | rails-96650f704a7a36097d634972484a305a639143c7.tar.gz rails-96650f704a7a36097d634972484a305a639143c7.tar.bz2 rails-96650f704a7a36097d634972484a305a639143c7.zip |
added block arguments to ActionController::Metal#use
Useful for cases such as warden, where a block configuration is taken.
class SomeController < ApplicationController
use RailsWarden::Manager do |manager|
manager.default_strategies :facebook_oauth
manager.failure_app = SomeController.action(:authorize)
end
end
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r-- | actionpack/test/controller/new_base/middleware_test.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/actionpack/test/controller/new_base/middleware_test.rb b/actionpack/test/controller/new_base/middleware_test.rb index 26a66c91a6..ccef060863 100644 --- a/actionpack/test/controller/new_base/middleware_test.rb +++ b/actionpack/test/controller/new_base/middleware_test.rb @@ -25,8 +25,25 @@ module MiddlewareTest result end end + + class BlockMiddleware + attr_accessor :configurable_message + def initialize(app, &block) + @app = app + yield(self) if block_given? + end + + def call(env) + result = @app.call(env) + result[1]["Configurable-Message"] = configurable_message + result + end + end class MyController < ActionController::Metal + use BlockMiddleware do |config| + config.configurable_message = "Configured by block." + end use MyMiddleware middleware.insert_before MyMiddleware, ExclaimerMiddleware @@ -67,6 +84,11 @@ module MiddlewareTest assert_equal "First!", result[1]["Middleware-Order"] end + test "middleware stack accepts block arguments" do + result = @app.call(env_for("/")) + assert_equal "Configured by block.", result[1]["Configurable-Message"] + end + test "middleware stack accepts only and except as options" do result = ActionsController.action(:show).call(env_for("/")) assert_equal "First!", result[1]["Middleware-Order"] |