aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller/caching_filestore.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-09-29 08:43:17 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-09-29 08:43:17 +0000
commit438db964ad1531d3c378c3e4acc25d0007cbc1cc (patch)
tree428239d889b10d66471a5c93d5fdf943e20b2032 /actionpack/test/controller/caching_filestore.rb
parent67d1e0cd3d366cd74caa24bc622442d04ef20e57 (diff)
downloadrails-438db964ad1531d3c378c3e4acc25d0007cbc1cc.tar.gz
rails-438db964ad1531d3c378c3e4acc25d0007cbc1cc.tar.bz2
rails-438db964ad1531d3c378c3e4acc25d0007cbc1cc.zip
Testing should also use a default REQUEST_METHOD
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2408 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/test/controller/caching_filestore.rb')
-rw-r--r--actionpack/test/controller/caching_filestore.rb62
1 files changed, 22 insertions, 40 deletions
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