aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller/filters_test.rb
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2006-09-27 04:55:44 +0000
committerRick Olson <technoweenie@gmail.com>2006-09-27 04:55:44 +0000
commite537de00d806368f21cc22bde118fb90c1b6fe2d (patch)
treef9ca6bac9e371238a10b385a1069576d26685cd8 /actionpack/test/controller/filters_test.rb
parent6a8dcc8a5bd9e8510c75d7a88a1072d88067aaa9 (diff)
downloadrails-e537de00d806368f21cc22bde118fb90c1b6fe2d.tar.gz
rails-e537de00d806368f21cc22bde118fb90c1b6fe2d.tar.bz2
rails-e537de00d806368f21cc22bde118fb90c1b6fe2d.zip
Fix bug that kept any before_filter except the first one from being able to halt the before_filter chain. [Rick Olson]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5196 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/test/controller/filters_test.rb')
-rw-r--r--actionpack/test/controller/filters_test.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb
index a8bb11f7eb..421758ac34 100644
--- a/actionpack/test/controller/filters_test.rb
+++ b/actionpack/test/controller/filters_test.rb
@@ -20,6 +20,26 @@ class FilterTest < Test::Unit::TestCase
@ran_after_filter << "clean_up"
end
end
+
+ class TestMultipleFiltersController < ActionController::Base
+ before_filter :try_1
+ before_filter :try_2
+ before_filter :try_3
+
+ (1..3).each do |i|
+ define_method "fail_#{i}" do
+ render :text => i.to_s
+ end
+ end
+
+ protected
+ (1..3).each do |i|
+ define_method "try_#{i}" do
+ instance_variable_set :@try, i
+ action_name != "fail_#{i}"
+ end
+ end
+ end
class RenderingController < ActionController::Base
before_filter :render_something_else
@@ -620,6 +640,30 @@ class YieldingAroundFiltersTest < Test::Unit::TestCase
assert_equal 'before around (before yield) around (after yield)',controller.template.assigns['ran_filter'].join(' ')
end
+ def test_first_filter_in_multiple_before_filter_chain_halts
+ controller = ::FilterTest::TestMultipleFiltersController.new
+ response = test_process(controller, 'fail_1')
+ assert_equal '', response.body
+ assert_equal 1, controller.instance_variable_get(:@try)
+ assert controller.instance_variable_get(:@before_filter_chain_aborted)
+ end
+
+ def test_second_filter_in_multiple_before_filter_chain_halts
+ controller = ::FilterTest::TestMultipleFiltersController.new
+ response = test_process(controller, 'fail_2')
+ assert_equal '', response.body
+ assert_equal 2, controller.instance_variable_get(:@try)
+ assert controller.instance_variable_get(:@before_filter_chain_aborted)
+ end
+
+ def test_last_filter_in_multiple_before_filter_chain_halts
+ controller = ::FilterTest::TestMultipleFiltersController.new
+ response = test_process(controller, 'fail_3')
+ assert_equal '', response.body
+ assert_equal 3, controller.instance_variable_get(:@try)
+ assert controller.instance_variable_get(:@before_filter_chain_aborted)
+ end
+
protected
def test_process(controller, action = "show")
request = ActionController::TestRequest.new