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

Changeset 5289

Show
Ignore:
Timestamp:
10/12/06 23:29:04 (2 years ago)
Author:
marcel
Message:

Make page caching respect the format of the resource that is being requested even if the current route is the default route so that, e.g. posts.rss is not transformed by url_for to '/' and subsequently cached as '/index.html' when it should be cached as '/posts.rss'.

Files:

Legend:

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

    r5288 r5289  
    11*SVN* 
     2 
     3* Make page caching respect the format of the resource that is being requested even if the current route is the default route so that, e.g. posts.rss is not transformed by url_for to '/' and subsequently cached as '/index.html' when it should be cached as '/posts.rss'.  [Marcel Molina Jr.] 
    24 
    35* Use String#chars in TextHelper::excerpt. Closes #6386 [Manfred Stienstra] 
  • trunk/actionpack/lib/action_controller/caching.rb

    r5248 r5289  
    119119        if options[:action].is_a?(Array) 
    120120          options[:action].dup.each do |action| 
    121             self.class.expire_page(url_for(options.merge({ :only_path => true, :skip_relative_url_root => true, :action => action }))) 
     121            self.class.expire_page(url_for(options.merge(:only_path => true, :skip_relative_url_root => true, :action => action))) 
    122122          end 
    123123        else 
    124           self.class.expire_page(url_for(options.merge({ :only_path => true, :skip_relative_url_root => true }))) 
     124          self.class.expire_page(url_for(options.merge(:only_path => true, :skip_relative_url_root => true))) 
    125125        end 
    126126      end 
     
    131131      def cache_page(content = nil, options = {}) 
    132132        return unless perform_caching && caching_allowed 
    133         self.class.cache_page(content || response.body, url_for(options.merge({ :only_path => true, :skip_relative_url_root => true }))) 
     133        self.class.cache_page(content || response.body, url_for(options.merge(:only_path => true, :skip_relative_url_root => true, :format => params[:format]))) 
    134134      end 
    135135 
  • trunk/actionpack/test/controller/caching_test.rb

    r5248 r5289  
    77ActionController::Base.perform_caching = true 
    88ActionController::Base.fragment_cache_store = :file_store, FILE_STORE_PATH 
     9 
     10class PageCachingTest < Test::Unit::TestCase 
     11  def setup 
     12    ActionController::Routing::Routes.draw do |map| 
     13      map.main '', :controller => 'posts' 
     14      map.resources :posts 
     15      map.connect ':controller/:action/:id' 
     16    end 
     17     
     18    @request = ActionController::TestRequest.new 
     19    @params = {:controller => 'posts', :action => 'index', :only_path => true, :skip_relative_url_root => true} 
     20    @rewriter = ActionController::UrlRewriter.new(@request, @params) 
     21  end  
     22 
     23  def test_page_caching_resources_saves_to_correct_path_with_extension_even_if_default_route 
     24    @params[:format] = 'rss' 
     25    assert_equal '/posts.rss', @rewriter.rewrite(@params) 
     26    @params[:format] = nil 
     27    assert_equal '/', @rewriter.rewrite(@params) 
     28  end 
     29end 
    930 
    1031class ActionCachingTestController < ActionController::Base