diff --git a/.travis.yml b/.travis.yml index 92a360e..cfe3e7a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,8 @@ rvm: - 1.9.3 - 2.0.0 - - 2.1.0 + - 2.1 + - 2.1.1 - jruby-19mode - jruby-head - rbx-19mode diff --git a/History.md b/History.md index 1949e3e..e56b3c5 100644 --- a/History.md +++ b/History.md @@ -3,6 +3,7 @@ ## 3.0.0 / not yet released / branch "master" * ... +* Properly set context rethrow_errors on render! #349 [Thierry Joyal, tjoyal] * Fix broken rendering of variables which are equal to false, see #345 [Florian Weingarten, fw42] * Remove ActionView template handler [Dylan Thacker-Smith, dylanahsmith] * Freeze lots of string literals for new Ruby 2.1 optimization, see #297 [Florian Weingarten, fw42] diff --git a/lib/liquid/context.rb b/lib/liquid/context.rb index dac1010..a35dcf2 100644 --- a/lib/liquid/context.rb +++ b/lib/liquid/context.rb @@ -15,6 +15,8 @@ module Liquid class Context attr_reader :scopes, :errors, :registers, :environments, :resource_limits + attr_accessor :rethrow_errors + def initialize(environments = {}, outer_scope = {}, registers = {}, rethrow_errors = false, resource_limits = {}) @environments = [environments].flatten @scopes = [(outer_scope || {})] diff --git a/lib/liquid/template.rb b/lib/liquid/template.rb index e04e0b5..d9c409b 100644 --- a/lib/liquid/template.rb +++ b/lib/liquid/template.rb @@ -113,7 +113,9 @@ module Liquid context = case args.first when Liquid::Context - args.shift + c = args.shift + c.rethrow_errors = true if @rethrow_errors + c when Liquid::Drop drop = args.shift drop.context = Context.new([drop, assigns], instance_assigns, registers, @rethrow_errors, @resource_limits) @@ -156,7 +158,8 @@ module Liquid end def render!(*args) - @rethrow_errors = true; render(*args) + @rethrow_errors = true + render(*args) end private diff --git a/test/integration/template_test.rb b/test/integration/template_test.rb index be853c7..54c1d42 100644 --- a/test/integration/template_test.rb +++ b/test/integration/template_test.rb @@ -22,6 +22,12 @@ class SomethingWithLength liquid_methods :length end +class ErroneousDrop < Liquid::Drop + def bad_method + raise 'ruby error in drop' + end +end + class TemplateTest < Test::Unit::TestCase include Liquid @@ -137,4 +143,14 @@ class TemplateTest < Test::Unit::TestCase assert_equal 'bar', t.parse('{{bar}}').render!(drop) assert_equal 'haha', t.parse("{{baz}}").render!(drop) end + + def test_render_bang_force_rethrow_errors_on_passed_context + context = Context.new({'drop' => ErroneousDrop.new}) + t = Template.new.parse('{{ drop.bad_method }}') + + e = assert_raises RuntimeError do + t.render!(context) + end + assert_equal 'ruby error in drop', e.message + end end