Skip to content
Browse files

Test that exceptions raised in filters are properly rescued

  • Loading branch information...
1 parent c69d8c0 commit 2e1132fad8fa2ab58476b9ecc30523ed02a43181 @jeremy jeremy committed Dec 30, 2008
Showing with 22 additions and 4 deletions.
  1. +7 −4 actionpack/lib/action_controller/base.rb
  2. +15 −0 actionpack/test/controller/rescue_test.rb
View
11 actionpack/lib/action_controller/base.rb
@@ -1350,9 +1350,12 @@ def process_cleanup
end
Base.class_eval do
- include Flash, Filters, Layout, Benchmarking, Rescue, MimeResponds, Helpers
- include Cookies, Caching, Verification, Streaming
- include SessionManagement, HttpAuthentication::Basic::ControllerMethods
- include RecordIdentifier, RequestForgeryProtection, Translation
+ [ Flash, Filters, Layout, Benchmarking, Rescue, MimeResponds, Helpers,
+ Cookies, Caching, Verification, Streaming, SessionManagement,
+ HttpAuthentication::Basic::ControllerMethods, RecordIdentifier,
+ RequestForgeryProtection, Translation
+ ].each do |mod|
+ include mod
+ end
end
end
View
15 actionpack/test/controller/rescue_test.rb
@@ -67,6 +67,11 @@ class ResourceUnavailableToRescueAsString < StandardError
render :text => 'no way'
end
+ before_filter(:only => :before_filter_raises) { raise 'umm nice' }
@ffmike
ffmike added a note Dec 31, 2008

I’m seeing an apparently-unrelated test fail after this commit: test_sweep_after_halted_filter_chain(FlashTest) is no longer passing. Commenting out the new before_filter fixes that other test. Same error on the Rails CI box: http://ci.rubyonrails.org/builds/rails/2e1132

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+ def before_filter_raises
+ end
+
def raises
render :text => 'already rendered'
raise "don't panic!"
@@ -154,6 +159,16 @@ def populate_exception_object
end
end
+ def test_rescue_exceptions_raised_by_filters
+ with_rails_root FIXTURE_PUBLIC do
+ with_all_requests_local false do
+ get :before_filter_raises
+ end
+ end
+
+ assert_response :internal_server_error
+ end
+
def test_rescue_action_locally_if_all_requests_local
@controller.expects(:local_request?).never
@controller.expects(:rescue_action_locally).with(@exception)

0 comments on commit 2e1132f

Please sign in to comment.
Something went wrong with that request. Please try again.