aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller/caching_filestore.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-04-30 15:29:27 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-04-30 15:29:27 +0000
commite6f3e5d90017f3f642dd2f4205679cc861a8a2ab (patch)
tree8522a30d273c2acd2ae640b2439f7f675661a69a /actionpack/test/controller/caching_filestore.rb
parent787951348bd498ef16e0c2f24aa677499bc6b1ef (diff)
downloadrails-e6f3e5d90017f3f642dd2f4205679cc861a8a2ab.tar.gz
rails-e6f3e5d90017f3f642dd2f4205679cc861a8a2ab.tar.bz2
rails-e6f3e5d90017f3f642dd2f4205679cc861a8a2ab.zip
Fixed action/fragment caching using the filestore when a directory and a file wanted to to use the same name. Now there's a .cache prefix that sidesteps the conflict #1188 [imbcmdth@hotmail.com]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1260 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/test/controller/caching_filestore.rb')
-rw-r--r--actionpack/test/controller/caching_filestore.rb92
1 files changed, 92 insertions, 0 deletions
diff --git a/actionpack/test/controller/caching_filestore.rb b/actionpack/test/controller/caching_filestore.rb
new file mode 100644
index 0000000000..e2478e9546
--- /dev/null
+++ b/actionpack/test/controller/caching_filestore.rb
@@ -0,0 +1,92 @@
+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
+ end
+
+ def write(message)
+ @last_message << message
+ end
+
+ def clear
+ @last_message = String.new
+ end
+end
+
+#setup our really sophisticated logger
+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'
+
+class TestController < ActionController::Base
+ caches_action :render_to_cache, :index
+
+ def render_to_cache
+ render_text "Render Cached"
+ end
+ alias :index :render_to_cache
+end
+
+class FileStoreTest < Test::Unit::TestCase
+ def setup
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.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
+ 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
+ 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
+ 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 ----")
+ TestLog.clear
+ end
+end \ No newline at end of file