From daa130bc840c0349a05f09506c15c53ac32740fd Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Fri, 27 Aug 2010 15:30:22 -0300 Subject: [PATCH 1/2] Add test to show double render error using with options and erb blocks --- actionpack/test/template/erb/form_for_test.rb | 2 +- actionpack/test/template/erb/tag_helper_test.rb | 4 ---- actionpack/test/template/erb/with_options_test.rb | 16 ++++++++++++++++ 3 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 actionpack/test/template/erb/with_options_test.rb diff --git a/actionpack/test/template/erb/form_for_test.rb b/actionpack/test/template/erb/form_for_test.rb index e722b40..aed5a2e 100644 --- a/actionpack/test/template/erb/form_for_test.rb +++ b/actionpack/test/template/erb/form_for_test.rb @@ -2,7 +2,7 @@ require "abstract_unit" require "template/erb/helper" module ERBTest - class TagHelperTest < BlockTestCase + class FormForTest < BlockTestCase test "form_for works" do output = render_content "form_for(:staticpage, :url => {:controller => 'blah', :action => 'update'})", "" assert_match %r{.*}, output diff --git a/actionpack/test/template/erb/tag_helper_test.rb b/actionpack/test/template/erb/tag_helper_test.rb index d073100..83d1bee 100644 --- a/actionpack/test/template/erb/tag_helper_test.rb +++ b/actionpack/test/template/erb/tag_helper_test.rb @@ -39,10 +39,6 @@ module ERBTest end class TagHelperTest < BlockTestCase - def block_helper(str, rest) - "<%= #{str} do %>#{rest}<% end %>" - end - include SharedTagHelpers end 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 From 3664f39e76e52082b70d04af5f55838fc7b7ff43 Mon Sep 17 00:00:00 2001 From: Krekoten' Marjan Date: Sat, 28 Aug 2010 22:18:20 +0300 Subject: [PATCH 2/2] Fix double render when caused by with_options [#4429 state:resolved] --- .../lib/action_view/template/handlers/erb.rb | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/actionpack/lib/action_view/template/handlers/erb.rb b/actionpack/lib/action_view/template/handlers/erb.rb index ce609e0..b808536 100644 --- a/actionpack/lib/action_view/template/handlers/erb.rb +++ b/actionpack/lib/action_view/template/handlers/erb.rb @@ -36,9 +36,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 << ');' -- 1.7.2