diff --git a/test/liquid/tags/include_tag_test.rb b/test/liquid/tags/include_tag_test.rb index 101dd7bc..8bdb19c8 100644 --- a/test/liquid/tags/include_tag_test.rb +++ b/test/liquid/tags/include_tag_test.rb @@ -39,6 +39,15 @@ class OtherFileSystem end end +class CountingFileSystem + attr_reader :count + def read_template_file(template_path, context) + @count ||= 0 + @count += 1 + 'from CountingFileSystem' + end +end + class IncludeTagTest < Test::Unit::TestCase include Liquid @@ -136,4 +145,22 @@ class IncludeTagTest < Test::Unit::TestCase assert_equal "Product: Draft 151cm ", Template.parse("{% include template for product %}").render("template" => 'product', 'product' => { 'title' => 'Draft 151cm'}) end -end # IncludeTagTest \ No newline at end of file + + def test_include_tag_caches_second_read_of_same_partial + file_system = CountingFileSystem.new + assert_equal 'from CountingFileSystemfrom CountingFileSystem', + Template.parse("{% include 'pick_a_source' %}{% include 'pick_a_source' %}").render({}, :registers => {:file_system => file_system}) + assert_equal 1, file_system.count + end + + def test_include_tag_doesnt_cache_partials_across_renders + file_system = CountingFileSystem.new + assert_equal 'from CountingFileSystem', + Template.parse("{% include 'pick_a_source' %}").render({}, :registers => {:file_system => file_system}) + assert_equal 1, file_system.count + + assert_equal 'from CountingFileSystem', + Template.parse("{% include 'pick_a_source' %}").render({}, :registers => {:file_system => file_system}) + assert_equal 2, file_system.count + end +end # IncludeTagTest