aboutsummaryrefslogtreecommitdiffstats
path: root/actionview
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2013-10-16 19:41:16 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2013-10-16 19:41:16 -0300
commitc44f8d255b3839142dd04c17b62ad57054ba41d4 (patch)
tree9c94a5e889c250fcf0ade2c661ee4fba462f97af /actionview
parent4fdde75b17734b26cba99d83bf06e175c896df34 (diff)
parent0cdce7f910708005acd99c80463e9efb3df942b0 (diff)
downloadrails-c44f8d255b3839142dd04c17b62ad57054ba41d4.tar.gz
rails-c44f8d255b3839142dd04c17b62ad57054ba41d4.tar.bz2
rails-c44f8d255b3839142dd04c17b62ad57054ba41d4.zip
Merge pull request #12540 from wyaeld/bug/fix-recursive-digest
Ensure ActionView::Digestor.cache is correctly cleaned up
Diffstat (limited to 'actionview')
-rw-r--r--actionview/CHANGELOG.md5
-rw-r--r--actionview/lib/action_view/digestor.rb12
-rw-r--r--actionview/test/template/digestor_test.rb26
3 files changed, 37 insertions, 6 deletions
diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md
index a09650c559..59b803d088 100644
--- a/actionview/CHANGELOG.md
+++ b/actionview/CHANGELOG.md
@@ -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.
diff --git a/actionview/lib/action_view/digestor.rb b/actionview/lib/action_view/digestor.rb
index af158a630b..5570e2a8dc 100644
--- a/actionview/lib/action_view/digestor.rb
+++ b/actionview/lib/action_view/digestor.rb
@@ -35,13 +35,13 @@ module ActionView
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
diff --git a/actionview/test/template/digestor_test.rb b/actionview/test/template/digestor_test.rb
index 0f6b14a57d..00bdfad3b7 100644
--- a/actionview/test/template/digestor_test.rb
+++ b/actionview/test/template/digestor_test.rb
@@ -217,6 +217,32 @@ class TemplateDigestorTest < ActionView::TestCase
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