Permalink
Browse files

Add conditional options to caches_page method [#25 state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information...
null-a authored and josh committed Apr 19, 2008
1 parent 3f8d3cd commit 14a40804a29a57ad05ca6bffbe1e5334089593a9
View
@@ -1,5 +1,7 @@
*SVN*
* Add conditional options to caches_page method. [Paul Horsfall]
* Move missing template logic to ActionView. [Pratik]
* Introduce ActionView::InlineTemplate class. [Pratik]
@@ -78,10 +78,18 @@ def cache_page(content, path)
# Caches the +actions+ using the page-caching approach that'll store the cache in a path within the page_cache_directory that
# matches the triggering url.
#
# Usage:
#
# # cache the index action
# caches_page :index
#
# # cache the index action except for JSON requests
# caches_page :index, :if => Proc.new { |c| !c.request.format.json? }
def caches_page(*actions)
return unless perform_caching
actions = actions.map(&:to_s)
after_filter { |c| c.cache_page if actions.include?(c.action_name) }
options = actions.extract_options!
after_filter({:only => actions}.merge(options)) { |c| c.cache_page }
end
private
@@ -8,7 +8,8 @@
ActionController::Base.cache_store = :file_store, FILE_STORE_PATH
class PageCachingTestController < ActionController::Base
caches_page :ok, :no_content, :found, :not_found
caches_page :ok, :no_content, :if => Proc.new { |c| !c.request.format.json? }
caches_page :found, :not_found
def ok
head :ok
@@ -127,6 +128,12 @@ def test_should_cache_ok_at_custom_path
end
end
end
def test_page_caching_conditional_options
@request.env['HTTP_ACCEPT'] = 'application/json'
get :ok
assert_page_not_cached :ok
end
private
def assert_page_cached(action, message = "#{action} should have been cached")

0 comments on commit 14a4080

Please sign in to comment.