Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #251 from tommay/master

Make Tilt::Cache return nil when nil is found in the cache.
  • Loading branch information...
commit a3322c6ca6a24f71de4a3d2258d57e8c2d44f5bb 2 parents 479d4c5 + 6c86b4e
Magnus Holm judofyr authored
Showing with 14 additions and 1 deletion.
  1. +3 −1 lib/tilt.rb
  2. +11 −0 test/tilt_cache_test.rb
4 lib/tilt.rb
View
@@ -85,7 +85,9 @@ def initialize
# @see Cache
def fetch(*key)
- @cache[key] ||= yield
+ @cache.fetch(key) do
+ @cache[key] = yield
+ end
end
# Clears the cache.
11 test/tilt_cache_test.rb
View
@@ -20,6 +20,17 @@ class TiltCacheTest < Minitest::Test
assert_same template, result
end
+ test "caching nil" do
+ called = false
+ result = @cache.fetch("blah") {called = true; nil}
+ assert_equal true, called
+ assert_nil result
+ called = false
+ result = @cache.fetch("blah") {called = true; :blah}
+ assert_equal false, called
+ assert_nil result
+ end
+
test "clearing the cache with #clear" do
template, other = nil
result = @cache.fetch('hello') { template = Tilt::StringTemplate.new {''} }
Please sign in to comment.
Something went wrong with that request. Please try again.