diff options
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r-- | actionpack/test/controller/filters_test.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index da6dee1540..5065cef859 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -3,6 +3,7 @@ require File.dirname(__FILE__) + '/../abstract_unit' class FilterTest < Test::Unit::TestCase class TestController < ActionController::Base before_filter :ensure_login + after_filter :clean_up def show render :inline => "ran action" @@ -13,6 +14,11 @@ class FilterTest < Test::Unit::TestCase @ran_filter ||= [] @ran_filter << "ensure_login" end + + def clean_up + @ran_after_filter ||= [] + @ran_after_filter << "clean_up" + end end class RenderingController < ActionController::Base @@ -108,6 +114,20 @@ class FilterTest < Test::Unit::TestCase end end + class ConditionalSkippingController < TestController + skip_before_filter :ensure_login, :only => [ :login ] + skip_after_filter :clean_up, :only => [ :login ] + + def login + render :inline => "ran action" + end + + def change_password + render :inline => "ran action" + end + end + + class ProcController < PrependingController before_filter(proc { |c| c.assigns["ran_proc_filter"] = true }) end @@ -343,6 +363,14 @@ class FilterTest < Test::Unit::TestCase end end + def test_conditional_skipping_of_filters + assert_nil test_process(ConditionalSkippingController, "login").template.assigns["ran_filter"] + assert_equal %w( ensure_login ), test_process(ConditionalSkippingController, "change_password").template.assigns["ran_filter"] + + assert_nil test_process(ConditionalSkippingController, "login").template.controller.instance_variable_get("@ran_after_filter") + assert_equal %w( clean_up ), test_process(ConditionalSkippingController, "change_password").template.controller.instance_variable_get("@ran_after_filter") + end + private def test_process(controller, action = "show") request = ActionController::TestRequest.new |