diff options
author | Daniel Schierbeck <dasch@zendesk.com> | 2013-07-15 15:59:18 +0200 |
---|---|---|
committer | Daniel Schierbeck <dasch@zendesk.com> | 2013-09-19 10:25:14 +0200 |
commit | 77e79ecd92acd43a282566e5d297b8e74dc14f05 (patch) | |
tree | b0b10448930bd2a4a8d2effb2e75cc1d7287c49a /actionview/test/template | |
parent | cb8174c57f46f3b11bc4662638539f45677d7dc1 (diff) | |
download | rails-77e79ecd92acd43a282566e5d297b8e74dc14f05.tar.gz rails-77e79ecd92acd43a282566e5d297b8e74dc14f05.tar.bz2 rails-77e79ecd92acd43a282566e5d297b8e74dc14f05.zip |
Bust the template digest cache key when details are changed
Since the lookup details will influence which template is resolved, they
need to be included in the cache key -- otherwise two different
templates may erroneously share the same digest value.
Diffstat (limited to 'actionview/test/template')
-rw-r--r-- | actionview/test/template/digestor_test.rb | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/actionview/test/template/digestor_test.rb b/actionview/test/template/digestor_test.rb index c6608e214a..0f6b14a57d 100644 --- a/actionview/test/template/digestor_test.rb +++ b/actionview/test/template/digestor_test.rb @@ -15,6 +15,16 @@ end class FixtureFinder FIXTURES_DIR = "#{File.dirname(__FILE__)}/../fixtures/digestor" + attr_reader :details + + def initialize + @details = {} + end + + def details_key + details.hash + end + def find(logical_name, keys, partial, options) FixtureTemplate.new("digestor/#{partial ? logical_name.gsub(%r|/([^/]+)$|, '/_\1') : logical_name}.#{options[:formats].first}.erb") end @@ -140,6 +150,20 @@ class TemplateDigestorTest < ActionView::TestCase end end + def test_details_are_included_in_cache_key + # Cache the template digest. + old_digest = digest("events/_event") + + # Change the template; the cached digest remains unchanged. + change_template("events/_event") + + # The details are changed, so a new cache key is generated. + finder.details[:foo] = "bar" + + # The cache is busted. + assert_not_equal old_digest, digest("events/_event") + end + def test_extra_whitespace_in_render_partial assert_digest_difference("messages/edit") do change_template("messages/_form") @@ -220,7 +244,11 @@ class TemplateDigestorTest < ActionView::TestCase end def digest(template_name, options={}) - ActionView::Digestor.digest(template_name, :html, FixtureFinder.new, options) + ActionView::Digestor.digest(template_name, :html, finder, options) + end + + def finder + @finder ||= FixtureFinder.new end def change_template(template_name) |