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

Changeset 7598

Show
Ignore:
Timestamp:
09/23/07 21:56:52 (1 year ago)
Author:
david
Message:

Fixed cache_page to use the request url instead of the routing options when picking a save path (closes #8614) [josh]

Files:

Legend:

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

    r7498 r7598  
    137137 
    138138      # Manually cache the +content+ in the key determined by +options+. If no content is provided, the contents of response.body is used 
    139       # If no options are provided, the current +options+ for this action is used. Example: 
     139      # If no options are provided, the requested url is used. Example: 
    140140      #   cache_page "I'm the cached content", :controller => "lists", :action => "show" 
    141       def cache_page(content = nil, options = {}
     141      def cache_page(content = nil, options = nil
    142142        return unless perform_caching && caching_allowed 
    143          
    144         if options.is_a?(Hash) 
    145           path = url_for(options.merge(:only_path => true, :skip_relative_url_root => true, :format => params[:format])) 
    146         else 
    147           path = options 
    148         end 
    149          
     143 
     144        path = case options 
     145          when Hash 
     146            url_for(options.merge(:only_path => true, :skip_relative_url_root => true, :format => params[:format])) 
     147          when String 
     148            options 
     149          else 
     150            request.path 
     151        end 
     152 
    150153        self.class.cache_page(content || response.body, path) 
    151154      end 
  • trunk/actionpack/test/controller/caching_test.rb

    r7348 r7598  
    9191    get :expire_custom_path 
    9292    assert !File.exist?("#{FILE_STORE_PATH}/index.html") 
     93  end 
     94 
     95  uses_mocha("should_cache_ok_at_custom_path") do 
     96    def test_should_cache_ok_at_custom_path 
     97      @request.expects(:path).returns("/index.html") 
     98      get :ok 
     99      assert_response :ok 
     100      assert File.exist?("#{FILE_STORE_PATH}/index.html") 
     101    end 
    93102  end 
    94103