diff options
author | José Valim <jose.valim@gmail.com> | 2010-05-30 15:53:14 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-05-30 15:53:14 +0200 |
commit | 9a93844aba44319d3c8487a554124beb00ccc267 (patch) | |
tree | 54348cbf7a6d5d96f8236dc1a9b69420134997db /actionpack/test/controller | |
parent | 0078df6b54e595421bb486613f7bc3693250b592 (diff) | |
download | rails-9a93844aba44319d3c8487a554124beb00ccc267.tar.gz rails-9a93844aba44319d3c8487a554124beb00ccc267.tar.bz2 rails-9a93844aba44319d3c8487a554124beb00ccc267.zip |
Add :only and :except to controllers MiddlewareStack. This allows
you to do the following:
class PostsController < ApplicationController
use AutheMiddleware, :except => [:index, :show]
end
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r-- | actionpack/test/controller/new_base/middleware_test.rb | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/actionpack/test/controller/new_base/middleware_test.rb b/actionpack/test/controller/new_base/middleware_test.rb index 65942ebc15..26a66c91a6 100644 --- a/actionpack/test/controller/new_base/middleware_test.rb +++ b/actionpack/test/controller/new_base/middleware_test.rb @@ -28,7 +28,6 @@ module MiddlewareTest class MyController < ActionController::Metal use MyMiddleware - middleware.insert_before MyMiddleware, ExclaimerMiddleware def index @@ -39,8 +38,23 @@ module MiddlewareTest class InheritedController < MyController end - module MiddlewareTests - extend ActiveSupport::Testing::Declarative + class ActionsController < ActionController::Metal + use MyMiddleware, :only => :show + middleware.insert_before MyMiddleware, ExclaimerMiddleware, :except => :index + + def index + self.response_body = "index" + end + + def show + self.response_body = "show" + end + end + + class TestMiddleware < ActiveSupport::TestCase + def setup + @app = MyController.action(:index) + end test "middleware that is 'use'd is called as part of the Rack application" do result = @app.call(env_for("/")) @@ -52,13 +66,13 @@ module MiddlewareTest result = @app.call(env_for("/")) assert_equal "First!", result[1]["Middleware-Order"] end - end - class TestMiddleware < ActiveSupport::TestCase - include MiddlewareTests + test "middleware stack accepts only and except as options" do + result = ActionsController.action(:show).call(env_for("/")) + assert_equal "First!", result[1]["Middleware-Order"] - def setup - @app = MyController.action(:index) + result = ActionsController.action(:index).call(env_for("/")) + assert_nil result[1]["Middleware-Order"] end def env_for(url) @@ -70,8 +84,5 @@ module MiddlewareTest def setup @app = InheritedController.action(:index) end - - test "middleware inherits" do - end end end |