Permalink
Browse files

created unit tests and fixed bug that failed tests

Signed-off-by: David Heinemeier Hansson <david@loudthinking.com>
  • Loading branch information...
1 parent 250dfb1 commit be1dbf321aba03c2e9bec423f753308e9bba3ef5 Thijs de Vries committed with dhh Jan 31, 2009
Showing with 22 additions and 2 deletions.
  1. +1 −1 activesupport/lib/active_support/cache.rb
  2. +21 −1 activesupport/test/caching_test.rb
View
2 activesupport/lib/active_support/cache.rb
@@ -138,7 +138,7 @@ def silence!
# 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
View
22 activesupport/test/caching_test.rb
@@ -90,7 +90,27 @@ def test_should_read_and_write_nil
@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' }

0 comments on commit be1dbf3

Please sign in to comment.