Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache#_fetch correctly handles cached 'false' #145

Merged
merged 1 commit into from
Nov 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/i18n/backend/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,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
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,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