Permalink
Browse files

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

Ensure ActionView::Digestor.cache is correctly cleaned up
  • Loading branch information...
2 parents 4fdde75 + 0cdce7f commit c44f8d255b3839142dd04c17b62ad57054ba41d4 @rafaelfranca rafaelfranca committed Oct 16, 2013
Showing with 37 additions and 6 deletions.
  1. +5 −0 actionview/CHANGELOG.md
  2. +6 −6 actionview/lib/action_view/digestor.rb
  3. +26 −0 actionview/test/template/digestor_test.rb
View
@@ -1,3 +1,8 @@
+* Ensure ActionView::Digestor.cache is correctly cleaned up when
+ combining recursive templates with ActionView::Resolver.caching = false
+
+ *wyaeld*
+
* Fix `collection_check_boxes` generated hidden input to use the name attribute provided
in the options hash.
@@ -35,13 +35,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
@@ -217,6 +217,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 c44f8d2

Please sign in to comment.