diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 3351ba5886bc61a926dda34bdbc94c1a7f931372..b27a5a5c1e389c8c6b64afb01f4551eae3c854ed 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* 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] + * Fixed missing id uniqueness in FormTag#radio_button #1207 [Jarkko] * Fixed assert_redirected_to to work with :only_path => false #1204 [Alisdair McDiarmid] diff --git a/actionpack/lib/action_controller/caching.rb b/actionpack/lib/action_controller/caching.rb index 5ea5ab94ec5c29b39f9d010cec051a5eb9920d25..7c384738d64bb5eb3fc115a79e1850f02e54fa56 100644 --- a/actionpack/lib/action_controller/caching.rb +++ b/actionpack/lib/action_controller/caching.rb @@ -375,7 +375,7 @@ def delete_matched(matcher, options) #:nodoc: private def real_file_path(name) - '%s/%s' % [@cache_path, name.gsub('?', '.').gsub(':', '.')] + '%s/%s.cache' % [@cache_path, name.gsub('?', '.').gsub(':', '.')] end def ensure_cache_path(path) diff --git a/actionpack/test/controller/caching_filestore.rb b/actionpack/test/controller/caching_filestore.rb new file mode 100644 index 0000000000000000000000000000000000000000..e2478e95469c6bb1ebfa3b8a1867f9d9d6b4a544 --- /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