Create new resource_limits hash on Template initialization

This commit is contained in:
Florian Weingarten
2013-05-31 09:41:59 -04:00
parent 2b17e24b16
commit 1e8c081b42
2 changed files with 10 additions and 1 deletions

View File

@@ -50,6 +50,7 @@ module Liquid
# creates a new <tt>Template</tt> from an array of tokens. Use <tt>Template.parse</tt> instead
def initialize
@resource_limits = {}
end
# Parse source code.
@@ -88,7 +89,7 @@ module Liquid
#
def render(*args)
return '' if @root.nil?
context = case args.first
when Liquid::Context
args.shift

View File

@@ -112,4 +112,12 @@ class TemplateTest < Test::Unit::TestCase
assert_equal "Liquid error: Memory limits exceeded", t.render()
assert t.resource_limits[:reached]
end
def test_resource_limits_hash_in_template_gets_updated_even_if_no_limits_are_set
t = Template.parse("{% for a in (1..100) %} {% assign foo = 1 %} {% endfor %}")
t.render()
assert t.resource_limits[:assign_score_current] > 0
assert t.resource_limits[:render_score_current] > 0
assert t.resource_limits[:render_length_current] > 0
end
end # TemplateTest