From 038139870825ad843b0683e5273dc4d11cb684b3 Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Sun, 23 Mar 2008 01:48:17 +0000 Subject: Fix regression from filter refactoring where re-adding a skipped filter resulted in it being called twice. [rick] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9080 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/CHANGELOG | 2 ++ actionpack/lib/action_controller/filters.rb | 3 +++ actionpack/test/controller/filters_test.rb | 33 +++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index cc6c692af6..bcc258acc2 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fix regression from filter refactoring where re-adding a skipped filter resulted in it being called twice. [rick] + * Refactor filters to use Active Support callbacks. #11235 [Josh Peek] * Fixed that polymorphic routes would modify the input array #11363 [thomas.lee] diff --git a/actionpack/lib/action_controller/filters.rb b/actionpack/lib/action_controller/filters.rb index a822ffe4e4..218a9c0b80 100644 --- a/actionpack/lib/action_controller/filters.rb +++ b/actionpack/lib/action_controller/filters.rb @@ -264,6 +264,9 @@ module ActionController #:nodoc: def skip_filter_in_chain(*filters, &test) filters, conditions = extract_options(filters) + filters.each do |filter| + if callback = find_callback(filter) then delete(callback) end + end if conditions.empty? update_filter_in_chain(filters, :skip => conditions, &test) end diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index 092eb45cab..3652c482f1 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -158,6 +158,30 @@ class FilterTest < Test::Unit::TestCase end end + class SkippingAndLimitedController < TestController + skip_before_filter :ensure_login + before_filter :ensure_login, :only => :index + + def index + render :text => 'ok' + end + + def public + end + end + + class SkippingAndReorderingController < TestController + skip_before_filter :ensure_login + before_filter :find_record + before_filter :ensure_login + + private + def find_record + @ran_filter ||= [] + @ran_filter << "find_record" + end + end + class ConditionalSkippingController < TestController skip_before_filter :ensure_login, :only => [ :login ] skip_after_filter :clean_up, :only => [ :login ] @@ -565,6 +589,15 @@ class FilterTest < Test::Unit::TestCase response = test_process(PrependingBeforeAndAfterController) assert_equal %w( before_all between_before_all_and_after_all after_all ), response.template.assigns["ran_filter"] end + + def test_skipping_and_limiting_controller + assert_equal %w( ensure_login ), test_process(SkippingAndLimitedController, "index").template.assigns["ran_filter"] + assert_nil test_process(SkippingAndLimitedController, "public").template.assigns["ran_filter"] + end + + def test_skipping_and_reordering_controller + assert_equal %w( find_record ensure_login ), test_process(SkippingAndReorderingController, "index").template.assigns["ran_filter"] + end def test_conditional_skipping_of_filters assert_nil test_process(ConditionalSkippingController, "login").template.assigns["ran_filter"] -- cgit v1.2.3