Skip to content

Commit

Permalink
Merge pull request #145 from ragalie/cache_false
Browse files Browse the repository at this point in the history
Cache#_fetch correctly handles cached 'false'
  • Loading branch information
radar committed Nov 17, 2016
2 parents 8e7c228 + d311ce4 commit 14b6a5c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/i18n/backend/cache.rb
Expand Up @@ -89,7 +89,8 @@ def fetch(cache_key, &block)
end

def _fetch(cache_key, &block)
result = I18n.cache_store.read(cache_key) and return result
result = I18n.cache_store.read(cache_key)
return result unless result.nil?
result = catch(:exception, &block)
I18n.cache_store.write(cache_key, result) unless result.is_a?(Proc)
result
Expand Down
6 changes: 6 additions & 0 deletions test/backend/cache_test.rb
Expand Up @@ -38,6 +38,12 @@ def teardown
assert_equal 'Bar', I18n.t(:bar)
end

test "translate returns a cached false response" do
I18n.backend.expects(:lookup).never
I18n.cache_store.expects(:read).returns(false)
assert_equal false, I18n.t(:foo)
end

test "still raises MissingTranslationData but also caches it" do
assert_raise(I18n::MissingTranslationData) { I18n.t(:missing, :raise => true) }
assert_raise(I18n::MissingTranslationData) { I18n.t(:missing, :raise => true) }
Expand Down

0 comments on commit 14b6a5c

Please sign in to comment.