Changeset 6669
- Timestamp:
- 05/06/07 04:10:26 (1 year ago)
- Files:
-
- trunk/actionpack/lib/action_controller/filters.rb (modified) (4 diffs)
- trunk/actionpack/test/controller/filters_test.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/lib/action_controller/filters.rb
r6649 r6669 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| … … 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 … … 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 … … 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 trunk/actionpack/test/controller/filters_test.rb
r6649 r6669 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 … … 292 300 self.action_name = params[:choose] 293 301 end 302 end 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'] 294 331 end 295 332 … … 425 462 assert_equal action, response.body 426 463 end 464 end 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"] 427 470 end 428 471