Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 5301

Show
Ignore:
Timestamp:
10/14/06 01:54:42 (2 years ago)
Author:
minam
Message:

make sure filters in subclasses with :only or :except conditions are treated like skip_filter calls

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/lib/action_controller/filters.rb

    r5268 r5301  
    249249      # will execute before the action on this controller is performed. 
    250250      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? 
    252255      end 
    253256 
     
    264267      # that run _after_ actions on this controller are performed. 
    265268      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? 
    267273      end 
    268274 
     
    598604          end 
    599605        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 
    600627    end 
    601628 
  • trunk/actionpack/test/controller/filters_test.rb

    r5268 r5301  
    2121      end 
    2222  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 
    2432  class TestMultipleFiltersController < ActionController::Base 
    2533    before_filter :try_1 
     
    424432  end 
    425433 
     434  def test_changing_the_requirements 
     435    assert_equal nil, test_process(ChangingTheRequirementsController, "go_wild").template.assigns['ran_filter'] 
     436  end 
     437 
    426438  private 
    427439    def test_process(controller, action = "show")