aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller/filters_test.rb
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2007-07-11 02:29:25 +0000
committerMichael Koziarski <michael@koziarski.com>2007-07-11 02:29:25 +0000
commite80fabbbf46cadb69c30e6125ef0422f96ca8b6b (patch)
treefe063546b649f3cea09b35e24b8e76ca7d946f23 /actionpack/test/controller/filters_test.rb
parentf7bd676c8d2fab1b22ede4e12242b37eb3336884 (diff)
downloadrails-e80fabbbf46cadb69c30e6125ef0422f96ca8b6b.tar.gz
rails-e80fabbbf46cadb69c30e6125ef0422f96ca8b6b.tar.bz2
rails-e80fabbbf46cadb69c30e6125ef0422f96ca8b6b.zip
Fix errors with around_filters which do not yield, restore 1.1 behaviour with after filters. Closes #8891 [skaes]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7177 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/test/controller/filters_test.rb')
-rw-r--r--actionpack/test/controller/filters_test.rb80
1 files changed, 73 insertions, 7 deletions
diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb
index a38e55fb52..8adee4c12f 100644
--- a/actionpack/test/controller/filters_test.rb
+++ b/actionpack/test/controller/filters_test.rb
@@ -324,9 +324,9 @@ class FilterTest < Test::Unit::TestCase
render :text => 'hello'
end
end
-
+
class ErrorToRescue < Exception; end
-
+
class RescuingAroundFilterWithBlock
def filter(controller)
begin
@@ -336,20 +336,86 @@ class FilterTest < Test::Unit::TestCase
end
end
end
-
+
class RescuedController < ActionController::Base
around_filter RescuingAroundFilterWithBlock.new
-
+
def show
raise ErrorToRescue.new("Something made the bad noise.")
end
-
+
private
def rescue_action(exception)
raise exception
end
end
+ class NonYieldingAroundFilterController < ActionController::Base
+
+ before_filter :filter_one
+ around_filter :non_yielding_filter
+ before_filter :filter_two
+ after_filter :filter_three
+
+ def index
+ render :inline => "index"
+ end
+
+ #make sure the controller complains
+ def rescue_action(e); raise e; end
+
+ private
+
+ def filter_one
+ @filters ||= []
+ @filters << "filter_one"
+ end
+
+ def filter_two
+ @filters << "filter_two"
+ end
+
+ def non_yielding_filter
+ @filters << "zomg it didn't yield"
+ @filter_return_value
+ end
+
+ def filter_three
+ @filters << "filter_three"
+ end
+
+ end
+
+ def test_non_yielding_around_filters_not_returning_false_do_not_raise
+ controller = NonYieldingAroundFilterController.new
+ controller.instance_variable_set "@filter_return_value", true
+ assert_nothing_raised do
+ test_process(controller, "index")
+ end
+ end
+
+ def test_non_yielding_around_filters_returning_false_do_not_raise
+ controller = NonYieldingAroundFilterController.new
+ controller.instance_variable_set "@filter_return_value", false
+ assert_nothing_raised do
+ test_process(controller, "index")
+ end
+ end
+
+ def test_after_filters_are_not_run_if_around_filter_returns_false
+ controller = NonYieldingAroundFilterController.new
+ controller.instance_variable_set "@filter_return_value", false
+ test_process(controller, "index")
+ assert_equal ["filter_one", "zomg it didn't yield"], controller.assigns['filters']
+ end
+
+ def test_after_filters_are_not_run_if_around_filter_does_not_yield
+ controller = NonYieldingAroundFilterController.new
+ controller.instance_variable_set "@filter_return_value", true
+ test_process(controller, "index")
+ assert_equal ["filter_one", "zomg it didn't yield"], controller.assigns['filters']
+ end
+
def test_empty_filter_chain
assert_equal 0, EmptyFilterChainController.filter_chain.size
assert test_process(EmptyFilterChainController).template.assigns['action_executed']
@@ -516,13 +582,13 @@ class FilterTest < Test::Unit::TestCase
def test_changing_the_requirements
assert_equal nil, test_process(ChangingTheRequirementsController, "go_wild").template.assigns['ran_filter']
end
-
+
def test_a_rescuing_around_filter
response = nil
assert_nothing_raised do
response = test_process(RescuedController)
end
-
+
assert response.success?
assert_equal("I rescued this: #<FilterTest::ErrorToRescue: Something made the bad noise.>", response.body)
end