aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller/filters_test.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2006-01-31 23:55:04 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2006-01-31 23:55:04 +0000
commit2504982945828d24c9b799c408d71576508b4c15 (patch)
tree153a081b3ee884894798bc6fa6f9adcb1eee6110 /actionpack/test/controller/filters_test.rb
parent2bf3fa076e822da1e55064ca7e9409af3fe52841 (diff)
downloadrails-2504982945828d24c9b799c408d71576508b4c15.tar.gz
rails-2504982945828d24c9b799c408d71576508b4c15.tar.bz2
rails-2504982945828d24c9b799c408d71576508b4c15.zip
Added :only and :except controls to skip_before/after_filter just like for when you add filters [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3504 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/test/controller/filters_test.rb')
-rw-r--r--actionpack/test/controller/filters_test.rb28
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