0
FILE_STORE_PATH = File.join(File.dirname(__FILE__), '/../temp/', CACHE_DIR)
0
ActionController::Base.page_cache_directory = FILE_STORE_PATH
0
ActionController::Base.cache_store = :file_store, FILE_STORE_PATH
0
+ActionController::Base.view_paths = [ File.dirname(__FILE__) + '/../fixtures/' ]
0
class PageCachingTestController < ActionController::Base
0
caches_page :ok, :no_content, :if => Proc.new { |c| !c.request.format.json? }
0
def test_page_caching_conditional_options
0
@request.env['HTTP_ACCEPT'] = 'application/json'
0
class ActionCachingTestController < ActionController::Base
0
- caches_action :index, :redirected, :forbidden
0
+ caches_action :index, :redirected, :forbidden
, :if => Proc.new { |c| !c.request.format.json? }0
caches_action :show, :cache_path => 'http://test.host/custom/show'
0
caches_action :edit, :cache_path => Proc.new { |c| c.params[:id] ? "http://test.host/#{c.params[:id]};edit" : "http://test.host/edit" }
0
+ caches_action :with_layout
0
+ layout 'talk_from_action.erb'
0
- @cache_this =
Time.now.to_f.to_s
0
+ @cache_this =
MockTime.now.to_f.to_s
0
render :text => @cache_this
0
headers["Status"] = "403 Forbidden"
0
+ @cache_this = MockTime.now.to_f.to_s
0
+ render :text => @cache_this, :layout => true
0
alias_method :show, :index
0
alias_method :edit, :index
0
+ alias_method :destroy, :index
0
expire_action :controller => 'action_caching_test', :action => 'index'
0
render :nothing => true
0
+ # Let Time spicy to assure that Time.now != Time.now
0
class ActionCachingMockController
0
assert_equal cached_time, @response.body
0
+ def test_simple_action_not_cached
0
+ cached_time = content_to_cache
0
+ assert_equal cached_time, @response.body
0
+ assert_cache_does_not_exist 'hostname.com/action_caching_test/destroy'
0
+ assert_not_equal cached_time, @response.body
0
+ def test_action_cache_with_layout
0
+ cached_time = content_to_cache
0
+ assert_not_equal cached_time, @response.body
0
+ assert_cache_exists 'hostname.com/action_caching_test/with_layout'
0
+ assert_not_equal cached_time, @response.body
0
+ assert_equal @response.body, read_fragment('hostname.com/action_caching_test/with_layout')
0
+ def test_action_cache_conditional_options
0
+ @request.env['HTTP_ACCEPT'] = 'application/json'
0
+ assert_cache_does_not_exist 'hostname.com/action_caching_test'
0
def test_action_cache_with_custom_cache_path
0
cached_time = content_to_cache
0
def assert_cache_exists(path)
0
- full_path =
File.join(FILE_STORE_PATH, "views", path + '.cache')
0
+ full_path =
cache_path(path)
0
assert File.exist?(full_path), "#{full_path.inspect} does not exist."
0
+ def assert_cache_does_not_exist(path)
0
+ full_path = cache_path(path)
0
+ assert !File.exist?(full_path), "#{full_path.inspect} should not exist."
0
+ File.join(FILE_STORE_PATH, 'views', path + '.cache')
0
+ def read_fragment(path)
0
+ @controller.read_fragment(path)
0
class FragmentCachingTestController < ActionController::Base
0
ActionController::Base.perform_caching = true
0
@store = ActiveSupport::Cache::MemoryStore.new
0
- ActionController::Base.cache_store = @store
0
+ ActionController::Base.cache_store = @store
0
@controller = FunctionalCachingController.new
0
@request = ActionController::TestRequest.new
0
@response = ActionController::TestResponse.new
0
This bit's fragment cached
0
assert_equal expected_body, @response.body
0
assert_equal "This bit's fragment cached", @store.read('views/test.host/functional_caching/fragment_cached')
0
def test_fragment_caching_in_partials
0
get :html_fragment_cached_with_partial
0
assert_response :success
0
assert_match /Fragment caching in a partial/, @response.body
0
assert_match "Fragment caching in a partial", @store.read('views/test.host/functional_caching/html_fragment_cached_with_partial')
0
def test_fragment_caching_in_rjs_partials
0
xhr :get, :js_fragment_cached_with_partial
0
assert_response :success
Comments
No one has commented yet.