From 856a4dcf1207e888b23016cac6a64582051aa0ff Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 18 Mar 2008 17:56:05 +0000 Subject: Refactor filters to use Active Support callbacks. Closes #11235. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9055 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/test/controller/dispatcher_test.rb | 2 +- actionpack/test/controller/filters_test.rb | 25 ++++++++++--------------- 2 files changed, 11 insertions(+), 16 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/dispatcher_test.rb b/actionpack/test/controller/dispatcher_test.rb index fe9789c698..c64defeed4 100644 --- a/actionpack/test/controller/dispatcher_test.rb +++ b/actionpack/test/controller/dispatcher_test.rb @@ -11,7 +11,7 @@ class DispatcherTest < Test::Unit::TestCase @output = StringIO.new ENV['REQUEST_METHOD'] = 'GET' - Dispatcher.instance_variable_set("@prepare_dispatch_callbacks", []) + Dispatcher.instance_variable_set("@prepare_dispatch_callbacks", ActiveSupport::Callbacks::CallbackChain.new) @dispatcher = Dispatcher.new(@output) end diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index 7cf2c9d318..092eb45cab 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -134,6 +134,11 @@ class FilterTest < Test::Unit::TestCase before_filter(ConditionalClassFilter, :ensure_login, Proc.new {|c| c.assigns["ran_proc_filter1"] = true }, :except => :show_without_filter) { |c| c.assigns["ran_proc_filter2"] = true} end + class ConditionalOptionsFilter < ConditionalFilterController + before_filter :ensure_login, :if => Proc.new { |c| true } + before_filter :clean_up_tmp, :if => Proc.new { |c| false } + end + class EmptyFilterChainController < TestController self.filter_chain.clear def show @@ -466,6 +471,11 @@ class FilterTest < Test::Unit::TestCase assert !response.template.assigns["ran_proc_filter2"] end + def test_running_conditional_options + response = test_process(ConditionalOptionsFilter) + assert_equal %w( ensure_login ), response.template.assigns["ran_filter"] + end + def test_running_collection_condition_filters assert_equal %w( ensure_login ), test_process(ConditionalCollectionFilterController).template.assigns["ran_filter"] assert_equal nil, test_process(ConditionalCollectionFilterController, "show_without_filter").template.assigns["ran_filter"] @@ -499,13 +509,6 @@ class FilterTest < Test::Unit::TestCase assert_equal nil, test_process(BeforeAndAfterConditionController, "show_without_filter").template.assigns["ran_filter"] end - def test_bad_filter - bad_filter_controller = Class.new(ActionController::Base) - assert_raises(ActionController::ActionControllerError) do - bad_filter_controller.before_filter 2 - end - end - def test_around_filter controller = test_process(AroundFilterController) assert controller.template.assigns["before_ran"] @@ -746,14 +749,6 @@ class YieldingAroundFiltersTest < Test::Unit::TestCase assert_equal 4, ControllerWithAllTypesOfFilters.filter_chain.size end - def test_wrong_filter_type - assert_raise ArgumentError do - Class.new PostsController do - around_filter lambda { yield } - end - end - end - def test_base controller = PostsController assert_nothing_raised { test_process(controller,'no_raise') } -- cgit v1.2.3