From 636c45fc58bcc19d7669a739ccd05ff475381f48 Mon Sep 17 00:00:00 2001 From: Christopher Medrela Date: Sun, 24 Feb 2013 16:49:28 +0100 Subject: Fixed #19890 -- ifchanged templatetag rendered its content twice The content of ifchanged template tag was rendered twice: first time, to compare it with the previous value and the second time, to return the rendered output. --- tests/regressiontests/templates/tests.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests') diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py index 28d85cae9d..e1e448acba 100644 --- a/tests/regressiontests/templates/tests.py +++ b/tests/regressiontests/templates/tests.py @@ -441,6 +441,18 @@ class Templates(TestCase): output1 = template.render(Context({'foo': range(3), 'get_value': lambda: next(gen1)})) self.assertEqual(output1, '[0,1,2,3]', 'Expected [0,1,2,3] in first template, got {0}'.format(output1)) + def test_ifchanged_render_once(self): + """ Test for ticket #19890. The content of ifchanged template tag was + rendered twice.""" + + template = Template('{% ifchanged %}{{ gen.next }}{% endifchanged %}') + def gen(): + for i in xrange(1,10): + yield 'iteration no %d' % i + + output = template.render(Context({'gen': gen()})) + self.assertEqual(output, 'iteration no 1') + def test_templates(self): template_tests = self.get_template_tests() filter_tests = filters.get_filter_tests() -- cgit v1.3