Ticket #8226: filter_speedup_filter_chain_ordering_trunk.patch
| File filter_speedup_filter_chain_ordering_trunk.patch, 4.1 kB (added by skaes, 2 years ago) |
|---|
-
actionpack/test/controller/filters_test.rb
old new 131 131 before_filter(ConditionalClassFilter, :ensure_login, Proc.new {|c| c.assigns["ran_proc_filter1"] = true }, :except => :show_without_filter) { |c| c.assigns["ran_proc_filter2"] = true} 132 132 end 133 133 134 class EmptyFilterChainController < TestController 135 self.filter_chain.clear 136 def show 137 @action_executed = true 138 render :text => "yawp!" 139 end 140 end 141 134 142 class PrependingController < TestController 135 143 prepend_before_filter :wonderful_life 136 144 # skip_before_filter :fire_flash … … 293 301 end 294 302 end 295 303 304 class PrependingBeforeAndAfterController < ActionController::Base 305 prepend_before_filter :before_all 306 prepend_after_filter :after_all 307 before_filter :between_before_all_and_after_all 308 309 def before_all 310 @ran_filter ||= [] 311 @ran_filter << 'before_all' 312 end 313 314 def after_all 315 @ran_filter ||= [] 316 @ran_filter << 'after_all' 317 end 318 319 def between_before_all_and_after_all 320 @ran_filter ||= [] 321 @ran_filter << 'between_before_all_and_after_all' 322 end 323 def show 324 render :text => 'hello' 325 end 326 end 327 328 def test_empty_filter_chain 329 assert_equal 0, EmptyFilterChainController.filter_chain.size 330 assert test_process(EmptyFilterChainController).template.assigns['action_executed'] 331 end 332 296 333 def test_added_filter_to_inheritance_graph 297 334 assert_equal [ :ensure_login ], TestController.before_filters 298 335 end … … 426 463 end 427 464 end 428 465 466 def test_running_prepended_before_and_after_filter 467 assert_equal 3, PrependingBeforeAndAfterController.filter_chain.length 468 response = test_process(PrependingBeforeAndAfterController) 469 assert_equal %w( before_all between_before_all_and_after_all after_all ), response.template.assigns["ran_filter"] 470 end 471 429 472 def test_conditional_skipping_of_filters 430 473 assert_nil test_process(ConditionalSkippingController, "login").template.assigns["ran_filter"] 431 474 assert_equal %w( ensure_login find_user ), test_process(ConditionalSkippingController, "change_password").template.assigns["ran_filter"] -
actionpack/lib/action_controller/filters.rb
old new 527 527 end 528 528 529 529 def find_filter_append_position(filters, filter_type) 530 # appending an after filter puts it at the end of the call chain 531 # before and around filters goe before the first after filter in the chain 530 532 unless filter_type == :after 531 533 filter_chain.each_with_index do |f,i| 532 534 return i if f.after? … … 536 538 end 537 539 538 540 def find_filter_prepend_position(filters, filter_type) 541 # prepending a before or around filter puts it at the front of the call chain 542 # after filters go before the first after filter in the chain 539 543 if filter_type == :after 540 544 filter_chain.each_with_index do |f,i| 541 545 return i if f.after? 542 546 end 547 return -1 543 548 end 544 549 return 0 545 550 end … … 684 689 685 690 def call_filters(chain, index, nesting) 686 691 # run before filters until we find an after filter or around filter 687 while true692 while chain[index] 688 693 filter, index = skip_excluded_filters(chain, index) 689 break unless filter 694 break unless filter # end of call chain reached 690 695 case filter.type 691 696 when :before 692 697 # invoke before filter … … 710 715 return index if aborted || nesting != 0 711 716 712 717 # run after filters, if any 713 while filter =chain[index]718 while chain[index] 714 719 filter, index = skip_excluded_filters(chain, index) 720 break unless filter 715 721 case filter.type 716 722 when :after 717 723 filter.run(self)