From 438db964ad1531d3c378c3e4acc25d0007cbc1cc Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 29 Sep 2005 08:43:17 +0000 Subject: Testing should also use a default REQUEST_METHOD git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2408 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/test/controller/caching_filestore.rb | 62 +++++++++---------------- 1 file changed, 22 insertions(+), 40 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/caching_filestore.rb b/actionpack/test/controller/caching_filestore.rb index e2478e9546..389ebe02fa 100644 --- a/actionpack/test/controller/caching_filestore.rb +++ b/actionpack/test/controller/caching_filestore.rb @@ -1,16 +1,15 @@ require 'fileutils' require File.dirname(__FILE__) + '/../abstract_unit' -#generate the greatest logging class that ever lived class TestLogDevice < Logger::LogDevice attr :last_message, true def initialize - @last_message=String.new + @last_message=String.new end def write(message) - @last_message << message + @last_message << message end def clear @@ -23,14 +22,13 @@ TestLog = TestLogDevice.new RAILS_DEFAULT_LOGGER = Logger.new(TestLog) ActionController::Base.logger = RAILS_DEFAULT_LOGGER -#generate a random key to ensure the cache is always in a different location -RANDOM_KEY = rand(99999999).to_s -FILE_STORE_PATH = File.dirname(__FILE__) + '/../temp/' + RANDOM_KEY -ActionController::Base.perform_caching = true -ActionController::Base.fragment_cache_store = ActionController::Caching::Fragments::FileStore.new(FILE_STORE_PATH) - -#setup the routing information...not sure if this does anything -ActionController::Routing::Routes.connect "test", :controller => 'test', :action => 'render_to_cache' +def use_store + #generate a random key to ensure the cache is always in a different location + RANDOM_KEY = rand(99999999).to_s + FILE_STORE_PATH = File.dirname(__FILE__) + '/../temp/' + RANDOM_KEY + ActionController::Base.perform_caching = true + ActionController::Base.fragment_cache_store = :file_store, FILE_STORE_PATH +end class TestController < ActionController::Base caches_action :render_to_cache, :index @@ -45,48 +43,32 @@ class FileStoreTest < Test::Unit::TestCase def setup @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new + @controller = TestController.new @request.host = "hostname.com" end - - #To prime the cache with hostname.com/test - def test_render_to_cache_prime_a - @request.path_parameters = {:controller => "test"} - assert_fragment_cached do process_request end - end - - #To prime the cache with hostname.com/test/render_to_cache - def test_render_to_cache_prime_b - @request.path_parameters = {:action => "render_to_cache", :controller => "test"} - assert_fragment_cached do process_request end + + def teardown + FileUtils.rm_rf(FILE_STORE_PATH) end - #To hit the cache with hostname.com/test - def test_render_to_cache_zhit_a - @request.path_parameters = {:controller => "test"} - assert_fragment_hit do process_request end + def test_render_cached + assert_fragment_cached { get :render_to_cache } + assert_fragment_hit { get :render_to_cache } end - #To hit the cache with hostname.com/test/render_to_cache - def test_render_to_cache_zhit_b - @request.path_parameters = {:action => "render_to_cache", :controller => "test"} - assert_fragment_hit do process_request end - end private - def process_request - TestController.process(@request, @response) - end - - def assert_fragment_cached(&proc) - proc.call + def assert_fragment_cached + yield assert(TestLog.last_message.include?("Cached fragment:"), "--ERROR-- FileStore write failed ----") assert(!TestLog.last_message.include?("Couldn't create cache directory:"), "--ERROR-- FileStore create directory failed ----") TestLog.clear end - def assert_fragment_hit(&proc) - proc.call - assert(TestLog.last_message.include?( "Fragment hit:"), "--ERROR-- Fragment not found in FileStore ----") + def assert_fragment_hit + yield + assert(TestLog.last_message.include?("Fragment read:"), "--ERROR-- Fragment not found in FileStore ----") + assert(!TestLog.last_message.include?("Cached fragment:"), "--ERROR-- Did cache ----") TestLog.clear end end \ No newline at end of file -- cgit v1.2.3