Ticket #2241: throw-to-abort-filters.patch
| File throw-to-abort-filters.patch, 2.1 kB (added by fbeausoleil@ftml.net, 3 years ago) |
|---|
-
actionpack/test/controller/filters_test.rb
old new 216 216 end 217 217 end 218 218 219 class AbortingFilterController < ActionController::Base 220 before_filter :aborting_request 221 222 def show 223 render_text "ran action" 224 end 225 226 private 227 def aborting_request 228 throw :abort 229 end 230 231 def rescue_action(e) raise(e) end 232 end 233 219 234 def test_added_filter_to_inheritance_graph 220 235 assert_equal [ :fire_flash, :ensure_login ], TestController.before_filters 221 236 end … … 342 357 end 343 358 end 344 359 360 def test_prevent_filter_execution_by_throwing_abort 361 response = test_process(AbortingFilterController) 362 assert response.body.empty?, 'nothing should have been rendered' 363 end 364 345 365 private 346 366 def test_process(controller, action = "show") 347 367 request = ActionController::TestRequest.new -
actionpack/lib/action_controller/filters.rb
old new 297 297 end 298 298 299 299 # Calls all the defined before-filter filters, which are added by using "before_filter :method". 300 # If any of the filters return false, no more filters will be executed and the action is aborted. 300 # A filter may cancel the request by doing one of the following: 301 # * +throw(:abort)+; 302 # * +return false+; 303 # * or performing the render itself. 304 # If any of these action is executed, the request will not call the regular action. 301 305 def before_action #:doc: 302 call_filters(self.class.before_filters) 306 catch(:abort) do 307 return call_filters(self.class.before_filters) 308 end 309 310 return false 303 311 end 304 312 305 313 # Calls all the defined after-filter filters, which are added by using "after_filter :method".