aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activesupport/lib/active_support/cache/file_store.rb4
-rw-r--r--activesupport/test/caching_test.rb27
2 files changed, 29 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb
index 7b6ca39091..437679cc05 100644
--- a/activesupport/lib/active_support/cache/file_store.rb
+++ b/activesupport/lib/active_support/cache/file_store.rb
@@ -9,13 +9,13 @@ module ActiveSupport
def read(name, options = nil)
super
- File.open(real_file_path(name), 'rb') { |f| f.read } rescue nil
+ File.open(real_file_path(name), 'rb') { |f| Marshal.load(f) } rescue nil
end
def write(name, value, options = nil)
super
ensure_cache_path(File.dirname(real_file_path(name)))
- File.atomic_write(real_file_path(name), cache_path) { |f| f.write(value) }
+ File.atomic_write(real_file_path(name), cache_path) { |f| Marshal.dump(value, f) }
rescue => e
RAILS_DEFAULT_LOGGER.error "Couldn't create cache directory: #{name} (#{e.message})" if RAILS_DEFAULT_LOGGER
end
diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb
index f3220d27aa..c5f7fb7fdd 100644
--- a/activesupport/test/caching_test.rb
+++ b/activesupport/test/caching_test.rb
@@ -70,3 +70,30 @@ uses_mocha 'high-level cache store tests' do
end
end
end
+
+class FileStoreTest < Test::Unit::TestCase
+ def setup
+ @cache = ActiveSupport::Cache.lookup_store(:file_store, Dir.pwd)
+ end
+
+ def test_should_read_and_write_strings
+ @cache.write('foo', 'bar')
+ assert_equal 'bar', @cache.read('foo')
+ ensure
+ File.delete("foo.cache")
+ end
+
+ def test_should_read_and_write_hash
+ @cache.write('foo', {:a => "b"})
+ assert_equal({:a => "b"}, @cache.read('foo'))
+ ensure
+ File.delete("foo.cache")
+ end
+
+ def test_should_read_and_write_nil
+ @cache.write('foo', nil)
+ assert_equal nil, @cache.read('foo')
+ ensure
+ File.delete("foo.cache")
+ end
+end