Permalink
Browse files

Merge pull request #12540 from wyaeld/bug/fix-recursive-digest

Ensure ActionView::Digestor.cache is correctly cleaned up

Conflicts:
	actionview/CHANGELOG.md
  • Loading branch information...
1 parent f96b383 commit 6fcad8cdbc515b98f958e6c5dac6c5b298ae737d @rafaelfranca rafaelfranca committed Oct 16, 2013
Showing with 32 additions and 6 deletions.
  1. +6 −6 actionpack/lib/action_view/digestor.rb
  2. +26 −0 actionpack/test/template/digestor_test.rb
@@ -32,13 +32,13 @@ def compute_and_store_digest(cache_key, name, format, finder, options) # called
Digestor
end
+ digest = klass.new(name, format, finder, options).digest
# Store the actual digest if config.cache_template_loading is true
- klass.new(name, format, finder, options).digest.tap do |digest|
- @@cache[cache_key] = digest if ActionView::Resolver.caching?
- end
- rescue Exception
- @@cache.delete_pair(cache_key, false) if pre_stored # something went wrong, make sure not to corrupt the @@cache
- raise
+ @@cache[cache_key] = stored_digest = digest if ActionView::Resolver.caching?
+ digest
+ ensure
+ # something went wrong or ActionView::Resolver.caching? is false, make sure not to corrupt the @@cache
+ @@cache.delete_pair(cache_key, false) if pre_stored && !stored_digest
end
end
@@ -193,6 +193,32 @@ def test_cache_template_loading
ActionView::Resolver.caching = resolver_before
end
+ def test_digest_cache_cleanup_with_recursion
+ first_digest = digest("level/_recursion")
+ second_digest = digest("level/_recursion")
+
+ assert first_digest
+
+ # If the cache is cleaned up correctly, subsequent digests should return the same
+ assert_equal first_digest, second_digest
+ end
+
+ def test_digest_cache_cleanup_with_recursion_and_template_caching_off
+ resolver_before = ActionView::Resolver.caching
+ ActionView::Resolver.caching = false
+
+ first_digest = digest("level/_recursion")
+ second_digest = digest("level/_recursion")
+
+ assert first_digest
+
+ # If the cache is cleaned up correctly, subsequent digests should return the same
+ assert_equal first_digest, second_digest
+
+ ActionView::Resolver.caching = resolver_before
+ end
+
+
private
def assert_logged(message)
old_logger = ActionView::Base.logger

0 comments on commit 6fcad8c

Please sign in to comment.