further differentiate between environments and only evaluate Procs once

This commit is contained in:
James MacAulay
2009-08-07 11:24:15 -04:00
parent c792c29066
commit 167825aa92
4 changed files with 55 additions and 28 deletions
+4 -5
View File
@@ -67,8 +67,7 @@ class ContextTest < Test::Unit::TestCase
include Liquid
def setup
@template = Liquid::Template.new
@context = Liquid::Context.new(@template.assigns, @template.registers)
@context = Liquid::Context.new
end
def test_variables
@@ -151,11 +150,11 @@ class ContextTest < Test::Unit::TestCase
end
end
context = Context.new(@template)
context = Context.new
context.add_filters(filter)
assert_equal 'hi? hi!', context.invoke(:hi, 'hi?')
context = Context.new(@template)
context = Context.new
assert_raises(FilterNotFound) {
context.invoke(:hi, 'hi?')
}
@@ -191,7 +190,7 @@ class ContextTest < Test::Unit::TestCase
end
end
context = Context.new(@template)
context = Context.new
methods_before = context.strainer.methods.map { |method| method.to_s }
context.add_filters(filter)
methods_after = context.strainer.methods.map { |method| method.to_s }
+18
View File
@@ -53,5 +53,23 @@ class TemplateTest < Test::Unit::TestCase
t.assigns['foo'] = 'from persistent assigns'
assert_equal 'from persistent assigns', t.parse("{{ foo }}").render
end
def test_lambda_is_called_once_from_persistent_assigns_over_multiple_parses_and_renders
t = Template.new
t.assigns['number'] = lambda { @global ||= 0; @global += 1 }
assert_equal '1', t.parse("{{number}}").render
assert_equal '1', t.parse("{{number}}").render
assert_equal '1', t.render
@global = nil
end
def test_lambda_is_called_once_from_custom_assigns_over_multiple_parses_and_renders
t = Template.new
assigns = {'number' => lambda { @global ||= 0; @global += 1 }}
assert_equal '1', t.parse("{{number}}").render(assigns)
assert_equal '1', t.parse("{{number}}").render(assigns)
assert_equal '1', t.render(assigns)
@global = nil
end
end