From 0baa8f8604e7766ce627120dfe572e09c247ef8c Mon Sep 17 00:00:00 2001 From: Philippe Huibonhoa Date: Thu, 29 Sep 2011 18:59:40 -0700 Subject: Added fix so that file store does not raise an exception when cache dir does not exist yet. This can happen if a delete_matched is called before anything is saved in the cache. --- activesupport/test/caching_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index b692a41312..793e62a74a 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -566,6 +566,13 @@ class FileStoreTest < ActiveSupport::TestCase assert path.split('/').all? { |dir_name| dir_name.size <= ActiveSupport::Cache::FileStore::FILENAME_MAX_SIZE} assert_equal 'B', File.basename(path) end + + def test_search_dir_when_directory_does_not_exist + ActiveSupport::Cache::FileStore.new('test').send(:search_dir, 'dir_does_not_exist') do |path| + flunk "search_dir yielded but should have done nothing" + end + assert true + end end class MemoryStoreTest < ActiveSupport::TestCase -- cgit v1.2.3 From 119a484e808898a7ff55a27326ad49d8d493eb59 Mon Sep 17 00:00:00 2001 From: Philippe Huibonhoa Date: Sun, 2 Oct 2011 01:39:52 -0700 Subject: Improved testing so that it tests the real functionality and not the private method. --- activesupport/test/caching_test.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index 793e62a74a..cb5362525f 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -567,11 +567,12 @@ class FileStoreTest < ActiveSupport::TestCase assert_equal 'B', File.basename(path) end - def test_search_dir_when_directory_does_not_exist - ActiveSupport::Cache::FileStore.new('test').send(:search_dir, 'dir_does_not_exist') do |path| - flunk "search_dir yielded but should have done nothing" + # If nothing has been stored in the cache, there is a chance the cache directory does not yet exist + # Ensure delete_matched gracefully handles this case + def test_delete_matched_when_cache_directory_does_not_exist + assert_nothing_raised(Exception) do + ActiveSupport::Cache::FileStore.new('/test/cache/directory').delete_matched(/does_not_exist/) end - assert true end end -- cgit v1.2.3