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

Changeset 2873

Show
Ignore:
Timestamp:
11/04/05 19:42:22 (3 years ago)
Author:
david
Message:

Added skip_before_filter/skip_after_filter for easier control of the filter chain in inheritance hierachies [DHH] Added short-hand to assert_tag so assert_tag :tag => "span" can be written as assert_tag "span" [DHH]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r2848 r2873  
    11*SVN* 
    22 
    3 * Added redirect_to :back as a short-hand for redirect_to(request.env["HTTP_REFERER"]) 
     3* Added short-hand to assert_tag so assert_tag :tag => "span" can be written as assert_tag "span" [DHH] 
     4 
     5* Added skip_before_filter/skip_after_filter for easier control of the filter chain in inheritance hierachies [DHH]. Example: 
     6 
     7    class ApplicationController < ActionController::Base 
     8      before_filter :authenticate 
     9    end 
     10     
     11    class WeblogController < ApplicationController 
     12      # will run the :authenticate filter 
     13    end 
     14     
     15    class SignupController < ActionController::Base 
     16      # will not run the :authenticate filter 
     17      skip_before_filter :authenticate 
     18    end 
     19 
     20* Added redirect_to :back as a short-hand for redirect_to(request.env["HTTP_REFERER"]) [DHH] 
    421 
    522* Change javascript_include_tag :defaults to not use script.aculo.us loader, which facilitates the use of plugins for future script.aculo.us and third party javascript extensions, and provide register_javascript_include_default for plugins to specify additional JavaScript files to load. Removed slider.js and builder.js from actionpack. [Thomas Fuchs] 
  • trunk/actionpack/lib/action_controller/assertions.rb

    r2749 r2873  
    222222      #   assert_tag :tag => "span" 
    223223      # 
     224      #   # assert that there is a "span" tag with id="x" 
     225      #   assert_tag :tag => "span", :attributes => { :id => "x" } 
     226      # 
     227      #   # assert that there is a "span" tag using the short-hand 
     228      #   assert_tag :span 
     229      # 
     230      #   # assert that there is a "span" tag with id="x" using the short-hand 
     231      #   assert_tag :span, :attributes => { :id => "x" } 
     232      # 
    224233      #   # assert that there is a "span" inside of a "div" 
    225234      #   assert_tag :tag => "span", :parent => { :tag => "div" } 
     
    249258      #              :descendant => { :tag => "span", 
    250259      #                               :child => /hello world/ } 
    251       def assert_tag(opts) 
    252         clean_backtrace do 
     260      def assert_tag(*opts) 
     261        clean_backtrace do 
     262          opts = opts.size > 1 ? opts.last.merge({ :tag => opts.first.to_s }) : opts.first 
    253263          tag = find_tag(opts) 
    254264          assert tag, "expected tag, but no tag found matching #{opts.inspect} in:\n#{@response.body.inspect}" 
     
    260270      def assert_no_tag(opts) 
    261271        clean_backtrace do 
     272          opts = opts.size > 1 ? opts.last.merge({ :tag => opts.first.to_s }) : opts.first 
    262273          tag = find_tag(opts) 
    263274          assert !tag, "expected no tag, but found tag matching #{opts.inspect} in:\n#{@response.body.inspect}" 
  • trunk/actionpack/lib/action_controller/filters.rb

    r2749 r2873  
    126126    #       report_result 
    127127    #     end 
     128    #   end 
     129    # 
     130    # == Filter chain skipping 
     131    # 
     132    # Some times its convenient to specify a filter chain in a superclass that'll hold true for the majority of the  
     133    # subclasses, but not necessarily all of them. The subclasses that behave in exception can then specify which filters 
     134    # they would like to be relieved of. Examples 
     135    # 
     136    #   class ApplicationController < ActionController::Base 
     137    #     before_filter :authenticate 
     138    #   end 
     139    # 
     140    #   class WeblogController < ApplicationController 
     141    #     # will run the :authenticate filter 
     142    #   end 
     143    # 
     144    #   class SignupController < ActionController::Base 
     145    #     # will not run the :authenticate filter 
     146    #     skip_before_filter :authenticate 
    128147    #   end 
    129148    # 
     
    229248      # Short-hand for append_around_filter since that's the most common of the two. 
    230249      alias :around_filter :append_around_filter 
     250       
     251      # Removes the specified filters from the +before+ filter chain. Note that this only works for skipping method-reference  
     252      # filters, not procs. This is especially useful for managing the chain in inheritance hierarchies where only one out 
     253      # of many sub-controllers need a different hierarchy. 
     254      def skip_before_filter(*filters) 
     255        for filter in filters.flatten 
     256          write_inheritable_attribute("before_filters", read_inheritable_attribute("before_filters") - [ filter ]) 
     257        end 
     258      end 
     259 
     260      # Removes the specified filters from the +after+ filter chain. Note that this only works for skipping method-reference  
     261      # filters, not procs. This is especially useful for managing the chain in inheritance hierarchies where only one out 
     262      # of many sub-controllers need a different hierarchy. 
     263      def skip_after_filter(*filters) 
     264        for filter in filters.flatten 
     265          write_inheritable_attribute("after_filters", read_inheritable_attribute("after_filters") - [ filter ]) 
     266        end 
     267      end 
    231268       
    232269      # Returns all the before filters for this class and all its ancestors. 
  • trunk/actionpack/test/controller/filters_test.rb

    r1915 r2873  
    100100  class PrependingController < TestController 
    101101    prepend_before_filter :wonderful_life 
     102    skip_before_filter :fire_flash 
    102103 
    103104    private 
     
    226227   
    227228  def test_prepending_filter 
    228     assert_equal [ :wonderful_life, :fire_flash, :ensure_login ], PrependingController.before_filters 
     229    assert_equal [ :wonderful_life, :ensure_login ], PrependingController.before_filters 
    229230  end 
    230231