提交 be1dbf32 编写于 作者: T Thijs de Vries 提交者: David Heinemeier Hansson

created unit tests and fixed bug that failed tests

Signed-off-by: NDavid Heinemeier Hansson <david@loudthinking.com>
上级 250dfb18
......@@ -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
......
......@@ -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' }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册