From acae5f3e0c3277b4686ff42da22ca2881dfee9c0 Mon Sep 17 00:00:00 2001 From: Krekoten' Marjan Date: Thu, 16 Sep 2010 16:27:49 +0300 Subject: [PATCH] Fix double render when caused by with_options [#4429 state:resolved] --- .../lib/action_view/template/handlers/erb.rb | 5 ++++- actionpack/test/template/erb/with_options_test.rb | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletions(-) create mode 100644 actionpack/test/template/erb/with_options_test.rb diff --git a/actionpack/lib/action_view/template/handlers/erb.rb b/actionpack/lib/action_view/template/handlers/erb.rb index 24e1e44..571cb40 100644 --- a/actionpack/lib/action_view/template/handlers/erb.rb +++ b/actionpack/lib/action_view/template/handlers/erb.rb @@ -29,9 +29,12 @@ module ActionView end BLOCK_EXPR = /\s+(do|\{)(\s*\|[^|]*\|)?\s*\Z/ + WITH_OPTIONS_EXPR = /with_options.*?\s+(do|\{)(\s*\|[^|]*\|)?\s*\Z/ def add_expr_literal(src, code) - if code =~ BLOCK_EXPR + if code =~ WITH_OPTIONS_EXPR + src << code + elsif code =~ BLOCK_EXPR src << '@output_buffer.append= ' << code else src << '@output_buffer.append= (' << code << ');' diff --git a/actionpack/test/template/erb/with_options_test.rb b/actionpack/test/template/erb/with_options_test.rb new file mode 100644 index 0000000..4e805b6 --- /dev/null +++ b/actionpack/test/template/erb/with_options_test.rb @@ -0,0 +1,16 @@ +require "abstract_unit" +require "template/erb/helper" + +module ERBTest + class WithOptionsTest < BlockTestCase + test "with_options works" do + output = render_content "with_options :size => 10", "<%= opt.text_field_tag 'hello', 'world' %>" + expected = '' + assert_equal expected, output + end + + def block_helper(str, rest) + "<%= #{str} do |opt| %>#{rest}<% end %>" + end + end +end \ No newline at end of file -- 1.7.2