Changeset 5301
- Timestamp:
- 10/14/06 01:54:42 (2 years ago)
- Files:
-
- trunk/actionpack/lib/action_controller/filters.rb (modified) (3 diffs)
- trunk/actionpack/test/controller/filters_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/lib/action_controller/filters.rb
r5268 r5301 249 249 # will execute before the action on this controller is performed. 250 250 def append_before_filter(*filters, &block) 251 append_filter_to_chain(filters, :before, &block) 251 new_filters, existing_filters = look_for_existing_filters(filters, :before) 252 253 append_filter_to_chain(new_filters, :before, &block) 254 skip_before_filter(existing_filters) unless existing_filters.empty? 252 255 end 253 256 … … 264 267 # that run _after_ actions on this controller are performed. 265 268 def append_after_filter(*filters, &block) 266 prepend_filter_to_chain(filters, :after, &block) 269 new_filters, existing_filters = look_for_existing_filters(filters, :after) 270 271 prepend_filter_to_chain(new_filters, :after, &block) 272 skip_after_filter(existing_filters) unless existing_filters.empty? 267 273 end 268 274 … … 598 604 end 599 605 end 606 607 def look_for_existing_filters(filters, which) 608 filters, options = extract_conditions(filters) 609 old_filters = [] 610 611 filter_chain.select(&"#{which}?".to_sym).each do |f| 612 old_filters << f.filter if filters.include?(f.filter) 613 end 614 615 new_filters = filters - old_filters + [options] 616 617 if options[:except] 618 old_filters << { :only => options[:except] } 619 elsif options[:only] 620 old_filters << { :except => options[:only] } 621 else 622 old_filters = [] 623 end 624 625 [new_filters, old_filters] 626 end 600 627 end 601 628 trunk/actionpack/test/controller/filters_test.rb
r5268 r5301 21 21 end 22 22 end 23 23 24 class ChangingTheRequirementsController < TestController 25 before_filter :ensure_login, :except => [:go_wild] 26 27 def go_wild 28 render :text => "gobble" 29 end 30 end 31 24 32 class TestMultipleFiltersController < ActionController::Base 25 33 before_filter :try_1 … … 424 432 end 425 433 434 def test_changing_the_requirements 435 assert_equal nil, test_process(ChangingTheRequirementsController, "go_wild").template.assigns['ran_filter'] 436 end 437 426 438 private 427 439 def test_process(controller, action = "show")