From 5a3f783e196b01054b8d3986c3918a998a60dfee Mon Sep 17 00:00:00 2001 From: Thijs de Vries Date: Sat, 31 Jan 2009 18:31:59 -0500 Subject: [PATCH] created unit tests and fixed bug that failed tests --- activesupport/lib/active_support/cache.rb | 2 +- activesupport/test/caching_test.rb | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index 83174d3..0f848c5 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -138,7 +138,7 @@ module ActiveSupport # cache.fetch("foo") # => nil def fetch(key, options = {}) @logger_off = true - if !options[:force] && value = read(key, options) + if !options[:force] && ((value = read(key, options)) || exist?(key, options)) @logger_off = false log("hit", key, options) value diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index 4e212f1..e5105e9 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -90,7 +90,27 @@ module CacheStoreBehavior @cache.write('foo', nil) assert_equal nil, @cache.read('foo') end - + + def test_should_read_and_write_false + @cache.write('foo', false) + assert_equal false, @cache.read('foo') + end + + def test_should_read_and_write_true + @cache.write('foo', true) + assert_equal true, @cache.read('foo') + end + + def test_fetch_false_without_cache_miss + @cache.write('foo', false) + assert_equal false, @cache.fetch('foo') { 'baz' } + end + + def test_fetch_nil_without_cache_miss + @cache.write('foo', nil) + assert_equal nil, @cache.fetch('foo') { 'baz' } + end + def test_fetch_without_cache_miss @cache.write('foo', 'bar') assert_equal 'bar', @cache.fetch('foo') { 'baz' } -- 1.5.6.4