Fixed cache_page to use the request url instead of the routing options when picking a save path (closes #8614) [josh]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7598 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
a6f49d9b78
commit
7d9fe04b1d
@ -136,15 +136,18 @@ def expire_page(options = {})
|
||||
end
|
||||
|
||||
# Manually cache the +content+ in the key determined by +options+. If no content is provided, the contents of response.body is used
|
||||
# If no options are provided, the current +options+ for this action is used. Example:
|
||||
# If no options are provided, the requested url is used. Example:
|
||||
# cache_page "I'm the cached content", :controller => "lists", :action => "show"
|
||||
def cache_page(content = nil, options = {})
|
||||
def cache_page(content = nil, options = nil)
|
||||
return unless perform_caching && caching_allowed
|
||||
|
||||
if options.is_a?(Hash)
|
||||
path = url_for(options.merge(:only_path => true, :skip_relative_url_root => true, :format => params[:format]))
|
||||
path = case options
|
||||
when Hash
|
||||
url_for(options.merge(:only_path => true, :skip_relative_url_root => true, :format => params[:format]))
|
||||
when String
|
||||
options
|
||||
else
|
||||
path = options
|
||||
request.path
|
||||
end
|
||||
|
||||
self.class.cache_page(content || response.body, path)
|
||||
|
@ -92,6 +92,15 @@ def test_should_expire_cache_with_custom_path
|
||||
assert !File.exist?("#{FILE_STORE_PATH}/index.html")
|
||||
end
|
||||
|
||||
uses_mocha("should_cache_ok_at_custom_path") do
|
||||
def test_should_cache_ok_at_custom_path
|
||||
@request.expects(:path).returns("/index.html")
|
||||
get :ok
|
||||
assert_response :ok
|
||||
assert File.exist?("#{FILE_STORE_PATH}/index.html")
|
||||
end
|
||||
end
|
||||
|
||||
[:ok, :no_content, :found, :not_found].each do |status|
|
||||
[:get, :post, :put, :delete].each do |method|
|
||||
unless method == :get and status == :ok
|
||||
|
Loading…
Reference in New Issue
Block a user