diff options
25 files changed, 273 insertions, 315 deletions
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index b2fcbfa554..eeebf335dc 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -156,10 +156,12 @@ module ActionView #:nodoc: attr_reader :finder attr_accessor :base_path, :assigns, :template_extension, :first_render attr_accessor :controller - + attr_writer :template_format attr_accessor :current_render_extension + attr_accessor :output_buffer + # Specify trim mode for the ERB compiler. Defaults to '-'. # See ERb documentation for suitable values. @@erb_trim_mode = '-' @@ -178,10 +180,7 @@ module ActionView #:nodoc: # that alert()s the caught exception (and then re-raises it). @@debug_rjs = false cattr_accessor :debug_rjs - - @@erb_variable = '_erbout' - cattr_accessor :erb_variable - + attr_internal :request delegate :request_forgery_protection_token, :template, :params, :session, :cookies, :response, :headers, @@ -259,7 +258,7 @@ If you are rendering a subtemplate, you must now use controller-like partial syn if partial_layout = options.delete(:layout) if block_given? wrap_content_for_layout capture(&block) do - concat(render(options.merge(:partial => partial_layout)), block.binding) + concat(render(options.merge(:partial => partial_layout))) end else wrap_content_for_layout render(options) do @@ -317,9 +316,10 @@ If you are rendering a subtemplate, you must now use controller-like partial syn private def wrap_content_for_layout(content) - original_content_for_layout = @content_for_layout - @content_for_layout = content - returning(yield) { @content_for_layout = original_content_for_layout } + original_content_for_layout, @content_for_layout = @content_for_layout, content + yield + ensure + @content_for_layout = original_content_for_layout end # Evaluate the local assigns and pushes them to the view. diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb index 9ea06568cf..25e62f78fb 100644 --- a/actionpack/lib/action_view/helpers/capture_helper.rb +++ b/actionpack/lib/action_view/helpers/capture_helper.rb @@ -31,20 +31,13 @@ module ActionView # </body></html> # def capture(*args, &block) - # execute the block - begin - buffer = eval(ActionView::Base.erb_variable, block.binding) - rescue - buffer = nil - end - - if buffer.nil? - capture_block(*args, &block).to_s + if @output_buffer + with_output_buffer { block.call(*args) } else - capture_erb_with_buffer(buffer, *args, &block).to_s + block.call(*args) end end - + # Calling content_for stores a block of markup in an identifier for later use. # You can make subsequent calls to the stored content in other templates or the layout # by passing the identifier as an argument to <tt>yield</tt>. @@ -121,40 +114,17 @@ module ActionView # named <tt>@content_for_#{name_of_the_content_block}</tt>. The preferred usage is now # <tt><%= yield :footer %></tt>. def content_for(name, content = nil, &block) - existing_content_for = instance_variable_get("@content_for_#{name}").to_s - new_content_for = existing_content_for + (block_given? ? capture(&block) : content) - instance_variable_set("@content_for_#{name}", new_content_for) + ivar = "@content_for_#{name}" + content = capture(&block) if block_given? + instance_variable_set(ivar, "#{instance_variable_get(ivar)}#{content}") end private - def capture_block(*args, &block) - block.call(*args) - end - - def capture_erb(*args, &block) - buffer = eval(ActionView::Base.erb_variable, block.binding) - capture_erb_with_buffer(buffer, *args, &block) - end - - def capture_erb_with_buffer(buffer, *args, &block) - pos = buffer.length - block.call(*args) - - # extract the block - data = buffer[pos..-1] - - # replace it in the original with empty string - buffer[pos..-1] = '' - - data - end - - def erb_content_for(name, &block) - eval "@content_for_#{name} = (@content_for_#{name} || '') + capture_erb(&block)" - end - - def block_content_for(name, &block) - eval "@content_for_#{name} = (@content_for_#{name} || '') + capture_block(&block)" + def with_output_buffer(buf = '') + @output_buffer, old_buffer = buf, @output_buffer + yield + ensure + @output_buffer = old_buffer end end end diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 0791feb9ac..63a932320e 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -249,9 +249,9 @@ module ActionView args.unshift object end - concat(form_tag(options.delete(:url) || {}, options.delete(:html) || {}), proc.binding) + concat(form_tag(options.delete(:url) || {}, options.delete(:html) || {})) fields_for(object_name, *(args << options), &proc) - concat('</form>', proc.binding) + concat('</form>') end def apply_form_for_options!(object_or_array, options) #:nodoc: diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index ca58f4ba26..3a97f1390f 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -407,10 +407,10 @@ module ActionView # # => <fieldset><legend>Your details</legend><p><input id="name" name="name" type="text" /></p></fieldset> def field_set_tag(legend = nil, &block) content = capture(&block) - concat(tag(:fieldset, {}, true), block.binding) - concat(content_tag(:legend, legend), block.binding) unless legend.blank? - concat(content, block.binding) - concat("</fieldset>", block.binding) + concat(tag(:fieldset, {}, true)) + concat(content_tag(:legend, legend)) unless legend.blank? + concat(content) + concat("</fieldset>") end private @@ -442,9 +442,9 @@ module ActionView def form_tag_in_block(html_options, &block) content = capture(&block) - concat(form_tag_html(html_options), block.binding) - concat(content, block.binding) - concat("</form>", block.binding) + concat(form_tag_html(html_options)) + concat(content) + concat("</form>") end def token_tag diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index 1ea3cbd74e..85b205c264 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -172,20 +172,17 @@ module ActionView # alert('All is good') # <% end -%> def javascript_tag(content_or_options_with_block = nil, html_options = {}, &block) - if block_given? - html_options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash) - content = capture(&block) - else - content = content_or_options_with_block - end + content = + if block_given? + html_options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash) + capture(&block) + else + content_or_options_with_block + end - javascript_tag = content_tag("script", javascript_cdata_section(content), html_options.merge(:type => Mime::JS)) - - if block_given? && block_is_within_action_view?(block) - concat(javascript_tag, block.binding) - else - javascript_tag - end + tag = content_tag("script", javascript_cdata_section(content), html_options.merge(:type => Mime::JS)) + + block_given? ? concat(tag) : tag end def javascript_cdata_section(content) #:nodoc: @@ -208,7 +205,7 @@ module ActionView private def block_is_within_action_view?(block) - eval("defined? _erbout", block.binding) + !@output_buffer.nil? end end diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb index 5a1012954e..a7c3b9ddc3 100644 --- a/actionpack/lib/action_view/helpers/prototype_helper.rb +++ b/actionpack/lib/action_view/helpers/prototype_helper.rb @@ -382,9 +382,9 @@ module ActionView args.unshift object end - concat(form_remote_tag(options), proc.binding) + concat(form_remote_tag(options)) fields_for(object_name, *(args << options), &proc) - concat('</form>', proc.binding) + concat('</form>') end alias_method :form_remote_for, :remote_form_for diff --git a/actionpack/lib/action_view/helpers/record_tag_helper.rb b/actionpack/lib/action_view/helpers/record_tag_helper.rb index 66c596f3a9..9bb235175e 100644 --- a/actionpack/lib/action_view/helpers/record_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/record_tag_helper.rb @@ -51,9 +51,8 @@ module ActionView prefix = args.first.is_a?(Hash) ? nil : args.shift options = args.first.is_a?(Hash) ? args.shift : {} concat content_tag(tag_name, capture(&block), - options.merge({ :class => "#{dom_class(record)} #{options[:class]}".strip, :id => dom_id(record, prefix) })), - block.binding + options.merge({ :class => "#{dom_class(record)} #{options[:class]}".strip, :id => dom_id(record, prefix) })) end end end -end
\ No newline at end of file +end diff --git a/actionpack/lib/action_view/helpers/tag_helper.rb b/actionpack/lib/action_view/helpers/tag_helper.rb index ba43b5e8ef..a8a5987b1f 100644 --- a/actionpack/lib/action_view/helpers/tag_helper.rb +++ b/actionpack/lib/action_view/helpers/tag_helper.rb @@ -68,12 +68,9 @@ module ActionView def content_tag(name, content_or_options_with_block = nil, options = nil, escape = true, &block) if block_given? options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash) - content = capture(&block) - content_tag = content_tag_string(name, content, options, escape) - block_is_within_action_view?(block) ? concat(content_tag, block.binding) : content_tag + concat(content_tag_string(name, capture(&block), options, escape)) else - content = content_or_options_with_block - content_tag_string(name, content, options, escape) + content_tag_string(name, content_or_options_with_block, options, escape) end end @@ -127,7 +124,7 @@ module ActionView end def block_is_within_action_view?(block) - eval("defined? _erbout", block.binding) + !@output_buffer.nil? end end end diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index 669a285424..f81f7eded6 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -15,18 +15,22 @@ module ActionView # # ==== Examples # <% - # concat "hello", binding + # concat "hello" # # is the equivalent of <%= "hello" %> # # if (logged_in == true): - # concat "Logged in!", binding + # concat "Logged in!" # else - # concat link_to('login', :action => login), binding + # concat link_to('login', :action => login) # end # # will either display "Logged in!" or a login link # %> - def concat(string, binding) - eval(ActionView::Base.erb_variable, binding) << string + def concat(string) + if @output_buffer && string + @output_buffer << string + else + string + end end if RUBY_VERSION < '1.9' diff --git a/actionpack/lib/action_view/template_handlers/builder.rb b/actionpack/lib/action_view/template_handlers/builder.rb index f76d89777a..ee02ce1a6f 100644 --- a/actionpack/lib/action_view/template_handlers/builder.rb +++ b/actionpack/lib/action_view/template_handlers/builder.rb @@ -11,10 +11,11 @@ module ActionView def compile(template) content_type_handler = (@view.send!(:controller).respond_to?(:response) ? "controller.response" : "controller") + "#{content_type_handler}.content_type ||= Mime::XML\n" + - "xml = ::Builder::XmlMarkup.new(:indent => 2)\n" + - template.source + - "\nxml.target!\n" + "xml = ::Builder::XmlMarkup.new(:indent => 2)\n" + + template.source + + "\nxml.target!\n" end def cache_fragment(block, name = {}, options = nil) diff --git a/actionpack/lib/action_view/template_handlers/compilable.rb b/actionpack/lib/action_view/template_handlers/compilable.rb index 25bd0fea7f..28c72172a0 100644 --- a/actionpack/lib/action_view/template_handlers/compilable.rb +++ b/actionpack/lib/action_view/template_handlers/compilable.rb @@ -106,7 +106,7 @@ module ActionView locals_code << "#{key} = local_assigns[:#{key}]\n" end - "def #{render_symbol}(local_assigns)\n#{locals_code}#{body}\nend" + "def #{render_symbol}(local_assigns)\nold_output_buffer = @output_buffer;#{locals_code}#{body}\nensure\n@output_buffer = old_output_buffer\nend" end # Return true if the given template was compiled for a superset of the keys in local_assigns @@ -125,4 +125,4 @@ module ActionView end end -end
\ No newline at end of file +end diff --git a/actionpack/lib/action_view/template_handlers/erb.rb b/actionpack/lib/action_view/template_handlers/erb.rb index 15a9064461..ad4ccc7c42 100644 --- a/actionpack/lib/action_view/template_handlers/erb.rb +++ b/actionpack/lib/action_view/template_handlers/erb.rb @@ -43,13 +43,11 @@ module ActionView include Compilable def compile(template) - ::ERB.new(template.source, nil, @view.erb_trim_mode).src + ::ERB.new(template.source, nil, @view.erb_trim_mode, '@output_buffer').src end def cache_fragment(block, name = {}, options = nil) #:nodoc: - @view.fragment_for(block, name, options) do - eval(ActionView::Base.erb_variable, block.binding) - end + @view.fragment_for(block, name, options) { @view.response.template.output_buffer ||= '' } end end end diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index c6d61bb504..aee60b1c6f 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -436,6 +436,8 @@ class FragmentCachingTest < Test::Unit::TestCase @controller.request = @request @controller.response = @response @controller.send(:initialize_current_url) + @controller.send(:initialize_template_class, @response) + @controller.send(:assign_shortcuts, @request, @response) end def test_fragment_cache_key @@ -525,7 +527,7 @@ class FragmentCachingTest < Test::Unit::TestCase def test_cache_erb_fragment @store.write('views/expensive', 'fragment content') - _erbout = 'generated till now -> ' + @controller.response.template.output_buffer = 'generated till now -> ' assert_equal( 'generated till now -> fragment content', ActionView::TemplateHandlers::ERB.new(@controller).cache_fragment(Proc.new{ }, 'expensive')) diff --git a/actionpack/test/controller/capture_test.rb b/actionpack/test/controller/capture_test.rb index aaafea3920..2604844b84 100644 --- a/actionpack/test/controller/capture_test.rb +++ b/actionpack/test/controller/capture_test.rb @@ -11,16 +11,8 @@ class CaptureController < ActionController::Base def content_for_with_parameter render :layout => "talk_from_action" end - - def content_for_concatenated - render :layout => "talk_from_action" - end - def erb_content_for - render :layout => "talk_from_action" - end - - def block_content_for + def content_for_concatenated render :layout => "talk_from_action" end @@ -62,21 +54,11 @@ class CaptureTest < Test::Unit::TestCase assert_equal expected_content_for_output, @response.body end - def test_erb_content_for - get :erb_content_for - assert_equal expected_content_for_output, @response.body - end - def test_should_set_content_for_with_parameter get :content_for_with_parameter assert_equal expected_content_for_output, @response.body end - def test_block_content_for - get :block_content_for - assert_equal expected_content_for_output, @response.body - end - def test_non_erb_block_content_for get :non_erb_block_content_for assert_equal expected_content_for_output, @response.body diff --git a/actionpack/test/fixtures/test/block_content_for.erb b/actionpack/test/fixtures/test/block_content_for.erb deleted file mode 100644 index 9510337365..0000000000 --- a/actionpack/test/fixtures/test/block_content_for.erb +++ /dev/null @@ -1,2 +0,0 @@ -<% block_content_for :title do 'Putting stuff in the title!' end %> -Great stuff!
\ No newline at end of file diff --git a/actionpack/test/fixtures/test/erb_content_for.erb b/actionpack/test/fixtures/test/erb_content_for.erb deleted file mode 100644 index c3bdd13643..0000000000 --- a/actionpack/test/fixtures/test/erb_content_for.erb +++ /dev/null @@ -1,2 +0,0 @@ -<% erb_content_for :title do %>Putting stuff in the title!<% end %> -Great stuff!
\ No newline at end of file diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index 0a7b19ba96..3399b03dd2 100755 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -1002,17 +1002,17 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.written_on = Date.new(2004, 6, 15) - _erbout = '' + @output_buffer = '' fields_for :post, @post do |f| - _erbout.concat f.date_select(:written_on) + @output_buffer.concat f.date_select(:written_on) end expected = "<select id='post_written_on_1i' name='post[written_on(1i)]'>\n<option value='1999'>1999</option>\n<option value='2000'>2000</option>\n<option value='2001'>2001</option>\n<option value='2002'>2002</option>\n<option value='2003'>2003</option>\n<option selected='selected' value='2004'>2004</option>\n<option value='2005'>2005</option>\n<option value='2006'>2006</option>\n<option value='2007'>2007</option>\n<option value='2008'>2008</option>\n<option value='2009'>2009</option>\n</select>\n" expected << "<select id='post_written_on_2i' name='post[written_on(2i)]'>\n<option value='1'>January</option>\n<option value='2'>February</option>\n<option value='3'>March</option>\n<option value='4'>April</option>\n<option value='5'>May</option>\n<option selected='selected' value='6'>June</option>\n<option value='7'>July</option>\n<option value='8'>August</option>\n<option value='9'>September</option>\n<option value='10'>October</option>\n<option value='11'>November</option>\n<option value='12'>December</option>\n</select>\n" expected << "<select id='post_written_on_3i' name='post[written_on(3i)]'>\n<option value='1'>1</option>\n<option value='2'>2</option>\n<option value='3'>3</option>\n<option value='4'>4</option>\n<option value='5'>5</option>\n<option value='6'>6</option>\n<option value='7'>7</option>\n<option value='8'>8</option>\n<option value='9'>9</option>\n<option value='10'>10</option>\n<option value='11'>11</option>\n<option value='12'>12</option>\n<option value='13'>13</option>\n<option value='14'>14</option>\n<option selected='selected' value='15'>15</option>\n<option value='16'>16</option>\n<option value='17'>17</option>\n<option value='18'>18</option>\n<option value='19'>19</option>\n<option value='20'>20</option>\n<option value='21'>21</option>\n<option value='22'>22</option>\n<option value='23'>23</option>\n<option value='24'>24</option>\n<option value='25'>25</option>\n<option value='26'>26</option>\n<option value='27'>27</option>\n<option value='28'>28</option>\n<option value='29'>29</option>\n<option value='30'>30</option>\n<option value='31'>31</option>\n</select>\n" - assert_dom_equal(expected, _erbout) + assert_dom_equal(expected, @output_buffer) end def test_date_select_with_index @@ -1287,10 +1287,10 @@ class DateHelperTest < ActionView::TestCase @post = Post.new @post.updated_at = Time.local(2004, 6, 15, 16, 35) - _erbout = '' + @output_buffer = '' fields_for :post, @post do |f| - _erbout.concat f.datetime_select(:updated_at) + @output_buffer.concat f.datetime_select(:updated_at) end expected = "<select id='post_updated_at_1i' name='post[updated_at(1i)]'>\n<option value='1999'>1999</option>\n<option value='2000'>2000</option>\n<option value='2001'>2001</option>\n<option value='2002'>2002</option>\n<option value='2003'>2003</option>\n<option selected='selected' value='2004'>2004</option>\n<option value='2005'>2005</option>\n<option value='2006'>2006</option>\n<option value='2007'>2007</option>\n<option value='2008'>2008</option>\n<option value='2009'>2009</option>\n</select>\n" @@ -1299,7 +1299,7 @@ class DateHelperTest < ActionView::TestCase expected << " — <select id='post_updated_at_4i' name='post[updated_at(4i)]'>\n<option value='00'>00</option>\n<option value='01'>01</option>\n<option value='02'>02</option>\n<option value='03'>03</option>\n<option value='04'>04</option>\n<option value='05'>05</option>\n<option value='06'>06</option>\n<option value='07'>07</option>\n<option value='08'>08</option>\n<option value='09'>09</option>\n<option value='10'>10</option>\n<option value='11'>11</option>\n<option value='12'>12</option>\n<option value='13'>13</option>\n<option value='14'>14</option>\n<option value='15'>15</option>\n<option selected='selected' value='16'>16</option>\n<option value='17'>17</option>\n<option value='18'>18</option>\n<option value='19'>19</option>\n<option value='20'>20</option>\n<option value='21'>21</option>\n<option value='22'>22</option>\n<option value='23'>23</option>\n</select>\n" expected << " : <select id='post_updated_at_5i' name='post[updated_at(5i)]'>\n<option value='00'>00</option>\n<option value='01'>01</option>\n<option value='02'>02</option>\n<option value='03'>03</option>\n<option value='04'>04</option>\n<option value='05'>05</option>\n<option value='06'>06</option>\n<option value='07'>07</option>\n<option value='08'>08</option>\n<option value='09'>09</option>\n<option value='10'>10</option>\n<option value='11'>11</option>\n<option value='12'>12</option>\n<option value='13'>13</option>\n<option value='14'>14</option>\n<option value='15'>15</option>\n<option value='16'>16</option>\n<option value='17'>17</option>\n<option value='18'>18</option>\n<option value='19'>19</option>\n<option value='20'>20</option>\n<option value='21'>21</option>\n<option value='22'>22</option>\n<option value='23'>23</option>\n<option value='24'>24</option>\n<option value='25'>25</option>\n<option value='26'>26</option>\n<option value='27'>27</option>\n<option value='28'>28</option>\n<option value='29'>29</option>\n<option value='30'>30</option>\n<option value='31'>31</option>\n<option value='32'>32</option>\n<option value='33'>33</option>\n<option value='34'>34</option>\n<option selected='selected' value='35'>35</option>\n<option value='36'>36</option>\n<option value='37'>37</option>\n<option value='38'>38</option>\n<option value='39'>39</option>\n<option value='40'>40</option>\n<option value='41'>41</option>\n<option value='42'>42</option>\n<option value='43'>43</option>\n<option value='44'>44</option>\n<option value='45'>45</option>\n<option value='46'>46</option>\n<option value='47'>47</option>\n<option value='48'>48</option>\n<option value='49'>49</option>\n<option value='50'>50</option>\n<option value='51'>51</option>\n<option value='52'>52</option>\n<option value='53'>53</option>\n<option value='54'>54</option>\n<option value='55'>55</option>\n<option value='56'>56</option>\n<option value='57'>57</option>\n<option value='58'>58</option>\n<option value='59'>59</option>\n</select>\n" - assert_dom_equal(expected, _erbout) + assert_dom_equal(expected, @output_buffer) end def test_date_select_with_zero_value_and_no_start_year diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index af99e6243d..65984fac44 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -337,14 +337,14 @@ class FormHelperTest < ActionView::TestCase end def test_form_for - _erbout = '' + @output_buffer = '' form_for(:post, @post, :html => { :id => 'create-post' }) do |f| - _erbout.concat f.label(:title) - _erbout.concat f.text_field(:title) - _erbout.concat f.text_area(:body) - _erbout.concat f.check_box(:secret) - _erbout.concat f.submit('Create post') + @output_buffer.concat f.label(:title) + @output_buffer.concat f.text_field(:title) + @output_buffer.concat f.text_area(:body) + @output_buffer.concat f.check_box(:secret) + @output_buffer.concat f.submit('Create post') end expected = @@ -357,16 +357,16 @@ class FormHelperTest < ActionView::TestCase "<input name='commit' id='post_submit' type='submit' value='Create post' />" + "</form>" - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end def test_form_for_with_method - _erbout = '' + @output_buffer = '' form_for(:post, @post, :html => { :id => 'create-post', :method => :put }) do |f| - _erbout.concat f.text_field(:title) - _erbout.concat f.text_area(:body) - _erbout.concat f.check_box(:secret) + @output_buffer.concat f.text_field(:title) + @output_buffer.concat f.text_area(:body) + @output_buffer.concat f.check_box(:secret) end expected = @@ -378,16 +378,16 @@ class FormHelperTest < ActionView::TestCase "<input name='post[secret]' type='hidden' value='0' />" + "</form>" - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end def test_form_for_without_object - _erbout = '' + @output_buffer = '' form_for(:post, :html => { :id => 'create-post' }) do |f| - _erbout.concat f.text_field(:title) - _erbout.concat f.text_area(:body) - _erbout.concat f.check_box(:secret) + @output_buffer.concat f.text_field(:title) + @output_buffer.concat f.text_area(:body) + @output_buffer.concat f.check_box(:secret) end expected = @@ -398,17 +398,17 @@ class FormHelperTest < ActionView::TestCase "<input name='post[secret]' type='hidden' value='0' />" + "</form>" - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end def test_form_for_with_index - _erbout = '' + @output_buffer = '' form_for("post[]", @post) do |f| - _erbout.concat f.label(:title) - _erbout.concat f.text_field(:title) - _erbout.concat f.text_area(:body) - _erbout.concat f.check_box(:secret) + @output_buffer.concat f.label(:title) + @output_buffer.concat f.text_field(:title) + @output_buffer.concat f.text_area(:body) + @output_buffer.concat f.check_box(:secret) end expected = @@ -420,16 +420,16 @@ class FormHelperTest < ActionView::TestCase "<input name='post[123][secret]' type='hidden' value='0' />" + "</form>" - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end def test_form_for_with_nil_index_option_override - _erbout = '' + @output_buffer = '' form_for("post[]", @post, :index => nil) do |f| - _erbout.concat f.text_field(:title) - _erbout.concat f.text_area(:body) - _erbout.concat f.check_box(:secret) + @output_buffer.concat f.text_field(:title) + @output_buffer.concat f.text_area(:body) + @output_buffer.concat f.check_box(:secret) end expected = @@ -440,14 +440,14 @@ class FormHelperTest < ActionView::TestCase "<input name='post[][secret]' type='hidden' value='0' />" + "</form>" - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end def test_nested_fields_for - _erbout = '' + @output_buffer = '' form_for(:post, @post) do |f| f.fields_for(:comment, @post) do |c| - _erbout.concat c.text_field(:title) + @output_buffer.concat c.text_field(:title) end end @@ -455,16 +455,16 @@ class FormHelperTest < ActionView::TestCase "<input name='post[comment][title]' size='30' type='text' id='post_comment_title' value='Hello World' />" + "</form>" - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end def test_fields_for - _erbout = '' + @output_buffer = '' fields_for(:post, @post) do |f| - _erbout.concat f.text_field(:title) - _erbout.concat f.text_area(:body) - _erbout.concat f.check_box(:secret) + @output_buffer.concat f.text_field(:title) + @output_buffer.concat f.text_area(:body) + @output_buffer.concat f.check_box(:secret) end expected = @@ -473,16 +473,16 @@ class FormHelperTest < ActionView::TestCase "<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" + "<input name='post[secret]' type='hidden' value='0' />" - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end def test_fields_for_with_index - _erbout = '' + @output_buffer = '' fields_for("post[]", @post) do |f| - _erbout.concat f.text_field(:title) - _erbout.concat f.text_area(:body) - _erbout.concat f.check_box(:secret) + @output_buffer.concat f.text_field(:title) + @output_buffer.concat f.text_area(:body) + @output_buffer.concat f.check_box(:secret) end expected = @@ -491,16 +491,16 @@ class FormHelperTest < ActionView::TestCase "<input name='post[123][secret]' checked='checked' type='checkbox' id='post_123_secret' value='1' />" + "<input name='post[123][secret]' type='hidden' value='0' />" - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end def test_fields_for_with_nil_index_option_override - _erbout = '' + @output_buffer = '' fields_for("post[]", @post, :index => nil) do |f| - _erbout.concat f.text_field(:title) - _erbout.concat f.text_area(:body) - _erbout.concat f.check_box(:secret) + @output_buffer.concat f.text_field(:title) + @output_buffer.concat f.text_area(:body) + @output_buffer.concat f.check_box(:secret) end expected = @@ -509,16 +509,16 @@ class FormHelperTest < ActionView::TestCase "<input name='post[][secret]' checked='checked' type='checkbox' id='post__secret' value='1' />" + "<input name='post[][secret]' type='hidden' value='0' />" - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end def test_fields_for_with_index_option_override - _erbout = '' + @output_buffer = '' fields_for("post[]", @post, :index => "abc") do |f| - _erbout.concat f.text_field(:title) - _erbout.concat f.text_area(:body) - _erbout.concat f.check_box(:secret) + @output_buffer.concat f.text_field(:title) + @output_buffer.concat f.text_area(:body) + @output_buffer.concat f.check_box(:secret) end expected = @@ -527,15 +527,15 @@ class FormHelperTest < ActionView::TestCase "<input name='post[abc][secret]' checked='checked' type='checkbox' id='post_abc_secret' value='1' />" + "<input name='post[abc][secret]' type='hidden' value='0' />" - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end def test_fields_for_without_object - _erbout = '' + @output_buffer = '' fields_for(:post) do |f| - _erbout.concat f.text_field(:title) - _erbout.concat f.text_area(:body) - _erbout.concat f.check_box(:secret) + @output_buffer.concat f.text_field(:title) + @output_buffer.concat f.text_area(:body) + @output_buffer.concat f.check_box(:secret) end expected = @@ -544,15 +544,15 @@ class FormHelperTest < ActionView::TestCase "<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" + "<input name='post[secret]' type='hidden' value='0' />" - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end def test_fields_for_with_only_object - _erbout = '' + @output_buffer = '' fields_for(@post) do |f| - _erbout.concat f.text_field(:title) - _erbout.concat f.text_area(:body) - _erbout.concat f.check_box(:secret) + @output_buffer.concat f.text_field(:title) + @output_buffer.concat f.text_area(:body) + @output_buffer.concat f.check_box(:secret) end expected = @@ -561,31 +561,31 @@ class FormHelperTest < ActionView::TestCase "<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" + "<input name='post[secret]' type='hidden' value='0' />" - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end def test_fields_for_object_with_bracketed_name - _erbout = '' + @output_buffer = '' fields_for("author[post]", @post) do |f| - _erbout.concat f.label(:title) - _erbout.concat f.text_field(:title) + @output_buffer.concat f.label(:title) + @output_buffer.concat f.text_field(:title) end assert_dom_equal "<label for=\"author_post_title\">Title</label>" + "<input name='author[post][title]' size='30' type='text' id='author_post_title' value='Hello World' />", - _erbout + @output_buffer end def test_fields_for_object_with_bracketed_name_and_index - _erbout = '' + @output_buffer = '' fields_for("author[post]", @post, :index => 1) do |f| - _erbout.concat f.label(:title) - _erbout.concat f.text_field(:title) + @output_buffer.concat f.label(:title) + @output_buffer.concat f.text_field(:title) end assert_dom_equal "<label for=\"author_post_1_title\">Title</label>" + "<input name='author[post][1][title]' size='30' type='text' id='author_post_1_title' value='Hello World' />", - _erbout + @output_buffer end def test_form_builder_does_not_have_form_for_method @@ -593,14 +593,14 @@ class FormHelperTest < ActionView::TestCase end def test_form_for_and_fields_for - _erbout = '' + @output_buffer = '' form_for(:post, @post, :html => { :id => 'create-post' }) do |post_form| - _erbout.concat post_form.text_field(:title) - _erbout.concat post_form.text_area(:body) + @output_buffer.concat post_form.text_field(:title) + @output_buffer.concat post_form.text_area(:body) fields_for(:parent_post, @post) do |parent_fields| - _erbout.concat parent_fields.check_box(:secret) + @output_buffer.concat parent_fields.check_box(:secret) end end @@ -612,18 +612,18 @@ class FormHelperTest < ActionView::TestCase "<input name='parent_post[secret]' type='hidden' value='0' />" + "</form>" - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end def test_form_for_and_fields_for_with_object - _erbout = '' + @output_buffer = '' form_for(:post, @post, :html => { :id => 'create-post' }) do |post_form| - _erbout.concat post_form.text_field(:title) - _erbout.concat post_form.text_area(:body) + @output_buffer.concat post_form.text_field(:title) + @output_buffer.concat post_form.text_area(:body) post_form.fields_for(@comment) do |comment_fields| - _erbout.concat comment_fields.text_field(:name) + @output_buffer.concat comment_fields.text_field(:name) end end @@ -634,7 +634,7 @@ class FormHelperTest < ActionView::TestCase "<input name='post[comment][name]' type='text' id='post_comment_name' value='new comment' size='30' />" + "</form>" - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end class LabelledFormBuilder < ActionView::Helpers::FormBuilder @@ -649,12 +649,12 @@ class FormHelperTest < ActionView::TestCase end def test_form_for_with_labelled_builder - _erbout = '' + @output_buffer = '' form_for(:post, @post, :builder => LabelledFormBuilder) do |f| - _erbout.concat f.text_field(:title) - _erbout.concat f.text_area(:body) - _erbout.concat f.check_box(:secret) + @output_buffer.concat f.text_field(:title) + @output_buffer.concat f.text_area(:body) + @output_buffer.concat f.check_box(:secret) end expected = @@ -665,18 +665,18 @@ class FormHelperTest < ActionView::TestCase "<input name='post[secret]' type='hidden' value='0' /><br/>" + "</form>" - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end def test_default_form_builder old_default_form_builder, ActionView::Base.default_form_builder = ActionView::Base.default_form_builder, LabelledFormBuilder - _erbout = '' + @output_buffer = '' form_for(:post, @post) do |f| - _erbout.concat f.text_field(:title) - _erbout.concat f.text_area(:body) - _erbout.concat f.check_box(:secret) + @output_buffer.concat f.text_field(:title) + @output_buffer.concat f.text_area(:body) + @output_buffer.concat f.check_box(:secret) end expected = @@ -687,17 +687,17 @@ class FormHelperTest < ActionView::TestCase "<input name='post[secret]' type='hidden' value='0' /><br/>" + "</form>" - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer ensure ActionView::Base.default_form_builder = old_default_form_builder end def test_default_form_builder_with_active_record_helpers - _erbout = '' + @output_buffer = '' form_for(:post, @post) do |f| - _erbout.concat f.error_message_on('author_name') - _erbout.concat f.error_messages + @output_buffer.concat f.error_message_on('author_name') + @output_buffer.concat f.error_messages end expected = %(<form action='http://www.example.com' method='post'>) + @@ -705,7 +705,7 @@ class FormHelperTest < ActionView::TestCase %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>) + %(</form>) - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end @@ -713,10 +713,10 @@ class FormHelperTest < ActionView::TestCase post = @post @post = nil - _erbout = '' + @output_buffer = '' form_for(:post, post) do |f| - _erbout.concat f.error_message_on('author_name') - _erbout.concat f.error_messages + @output_buffer.concat f.error_message_on('author_name') + @output_buffer.concat f.error_messages end expected = %(<form action='http://www.example.com' method='post'>) + @@ -724,19 +724,19 @@ class FormHelperTest < ActionView::TestCase %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>) + %(</form>) - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end # Perhaps this test should be moved to prototype helper tests. def test_remote_form_for_with_labelled_builder self.extend ActionView::Helpers::PrototypeHelper - _erbout = '' + @output_buffer = '' remote_form_for(:post, @post, :builder => LabelledFormBuilder) do |f| - _erbout.concat f.text_field(:title) - _erbout.concat f.text_area(:body) - _erbout.concat f.check_box(:secret) + @output_buffer.concat f.text_field(:title) + @output_buffer.concat f.text_area(:body) + @output_buffer.concat f.check_box(:secret) end expected = @@ -747,16 +747,16 @@ class FormHelperTest < ActionView::TestCase "<input name='post[secret]' type='hidden' value='0' /><br/>" + "</form>" - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end def test_fields_for_with_labelled_builder - _erbout = '' + @output_buffer = '' fields_for(:post, @post, :builder => LabelledFormBuilder) do |f| - _erbout.concat f.text_field(:title) - _erbout.concat f.text_area(:body) - _erbout.concat f.check_box(:secret) + @output_buffer.concat f.text_field(:title) + @output_buffer.concat f.text_area(:body) + @output_buffer.concat f.check_box(:secret) end expected = @@ -765,28 +765,28 @@ class FormHelperTest < ActionView::TestCase "<label for='secret'>Secret:</label> <input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" + "<input name='post[secret]' type='hidden' value='0' /><br/>" - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end def test_form_for_with_html_options_adds_options_to_form_tag - _erbout = '' + @output_buffer = '' form_for(:post, @post, :html => {:id => 'some_form', :class => 'some_class'}) do |f| end expected = "<form action=\"http://www.example.com\" class=\"some_class\" id=\"some_form\" method=\"post\"></form>" - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end def test_form_for_with_string_url_option - _erbout = '' + @output_buffer = '' form_for(:post, @post, :url => 'http://www.otherdomain.com') do |f| end - assert_equal '<form action="http://www.otherdomain.com" method="post"></form>', _erbout + assert_equal '<form action="http://www.otherdomain.com" method="post"></form>', @output_buffer end def test_form_for_with_hash_url_option - _erbout = '' + @output_buffer = '' form_for(:post, @post, :url => {:controller => 'controller', :action => 'action'}) do |f| end @@ -795,25 +795,25 @@ class FormHelperTest < ActionView::TestCase end def test_form_for_with_record_url_option - _erbout = '' + @output_buffer = '' form_for(:post, @post, :url => @post) do |f| end expected = "<form action=\"/posts/123\" method=\"post\"></form>" - assert_equal expected, _erbout + assert_equal expected, @output_buffer end def test_form_for_with_existing_object - _erbout = '' + @output_buffer = '' form_for(@post) do |f| end expected = "<form action=\"/posts/123\" class=\"edit_post\" id=\"edit_post_123\" method=\"post\"><div style=\"margin:0;padding:0\"><input name=\"_method\" type=\"hidden\" value=\"put\" /></div></form>" - assert_equal expected, _erbout + assert_equal expected, @output_buffer end def test_form_for_with_new_object - _erbout = '' + @output_buffer = '' post = Post.new post.new_record = true @@ -822,64 +822,64 @@ class FormHelperTest < ActionView::TestCase form_for(post) do |f| end expected = "<form action=\"/posts\" class=\"new_post\" id=\"new_post\" method=\"post\"></form>" - assert_equal expected, _erbout + assert_equal expected, @output_buffer end def test_form_for_with_existing_object_in_list @post.new_record = false @comment.save - _erbout = '' + @output_buffer = '' form_for([@post, @comment]) {} expected = %(<form action="#{comment_path(@post, @comment)}" class="edit_comment" id="edit_comment_1" method="post"><div style="margin:0;padding:0"><input name="_method" type="hidden" value="put" /></div></form>) - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end def test_form_for_with_new_object_in_list @post.new_record = false - _erbout = '' + @output_buffer = '' form_for([@post, @comment]) {} expected = %(<form action="#{comments_path(@post)}" class="new_comment" id="new_comment" method="post"></form>) - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end def test_form_for_with_existing_object_and_namespace_in_list @post.new_record = false @comment.save - _erbout = '' + @output_buffer = '' form_for([:admin, @post, @comment]) {} expected = %(<form action="#{admin_comment_path(@post, @comment)}" class="edit_comment" id="edit_comment_1" method="post"><div style="margin:0;padding:0"><input name="_method" type="hidden" value="put" /></div></form>) - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end def test_form_for_with_new_object_and_namespace_in_list @post.new_record = false - _erbout = '' + @output_buffer = '' form_for([:admin, @post, @comment]) {} expected = %(<form action="#{admin_comments_path(@post)}" class="new_comment" id="new_comment" method="post"></form>) - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end def test_form_for_with_existing_object_and_custom_url - _erbout = '' + @output_buffer = '' form_for(@post, :url => "/super_posts") do |f| end expected = "<form action=\"/super_posts\" class=\"edit_post\" id=\"edit_post_123\" method=\"post\"><div style=\"margin:0;padding:0\"><input name=\"_method\" type=\"hidden\" value=\"put\" /></div></form>" - assert_equal expected, _erbout + assert_equal expected, @output_buffer end def test_remote_form_for_with_html_options_adds_options_to_form_tag self.extend ActionView::Helpers::PrototypeHelper - _erbout = '' + @output_buffer = '' remote_form_for(:post, @post, :html => {:id => 'some_form', :class => 'some_class'}) do |f| end expected = "<form action=\"http://www.example.com\" class=\"some_class\" id=\"some_form\" method=\"post\" onsubmit=\"new Ajax.Request('http://www.example.com', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\"></form>" - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index 48a26deea9..3c9fb297c3 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -231,15 +231,15 @@ class FormOptionsHelperTest < ActionView::TestCase @post = Post.new @post.category = "<mus>" - _erbout = '' + @output_buffer = '' fields_for :post, @post do |f| - _erbout.concat f.select(:category, %w( abe <mus> hest)) + @output_buffer.concat f.select(:category, %w( abe <mus> hest)) end assert_dom_equal( "<select id=\"post_category\" name=\"post[category]\"><option value=\"abe\">abe</option>\n<option value=\"<mus>\" selected=\"selected\"><mus></option>\n<option value=\"hest\">hest</option></select>", - _erbout + @output_buffer ) end @@ -353,15 +353,15 @@ class FormOptionsHelperTest < ActionView::TestCase @post = Post.new @post.author_name = "Babe" - _erbout = '' + @output_buffer = '' fields_for :post, @post do |f| - _erbout.concat f.collection_select(:author_name, @posts, :author_name, :author_name) + @output_buffer.concat f.collection_select(:author_name, @posts, :author_name, :author_name) end assert_dom_equal( "<select id=\"post_author_name\" name=\"post[author_name]\"><option value=\"<Abe>\"><Abe></option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>", - _erbout + @output_buffer ) end @@ -1195,10 +1195,10 @@ COUNTRIES def test_time_zone_select_under_fields_for @firm = Firm.new("D") - _erbout = '' + @output_buffer = '' fields_for :firm, @firm do |f| - _erbout.concat f.time_zone_select(:time_zone) + @output_buffer.concat f.time_zone_select(:time_zone) end assert_dom_equal( @@ -1209,7 +1209,7 @@ COUNTRIES "<option value=\"D\" selected=\"selected\">D</option>\n" + "<option value=\"E\">E</option>" + "</select>", - _erbout + @output_buffer ) end diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index 73a8bd4d87..b281db18bd 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -43,19 +43,19 @@ class FormTagHelperTest < ActionView::TestCase end def test_form_tag_with_block - _erbout = '' - form_tag("http://example.com") { _erbout.concat "Hello world!" } + @output_buffer = '' + form_tag("http://example.com") { @output_buffer.concat "Hello world!" } expected = %(<form action="http://example.com" method="post">Hello world!</form>) - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end def test_form_tag_with_block_and_method - _erbout = '' - form_tag("http://example.com", :method => :put) { _erbout.concat "Hello world!" } + @output_buffer = '' + form_tag("http://example.com", :method => :put) { @output_buffer.concat "Hello world!" } expected = %(<form action="http://example.com" method="post"><div style='margin:0;padding:0'><input type="hidden" name="_method" value="put" /></div>Hello world!</form>) - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end def test_hidden_field_tag @@ -234,23 +234,23 @@ class FormTagHelperTest < ActionView::TestCase end def test_field_set_tag - _erbout = '' - field_set_tag("Your details") { _erbout.concat "Hello world!" } + @output_buffer = '' + field_set_tag("Your details") { @output_buffer.concat "Hello world!" } expected = %(<fieldset><legend>Your details</legend>Hello world!</fieldset>) - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer - _erbout = '' - field_set_tag { _erbout.concat "Hello world!" } + @output_buffer = '' + field_set_tag { @output_buffer.concat "Hello world!" } expected = %(<fieldset>Hello world!</fieldset>) - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer - _erbout = '' - field_set_tag('') { _erbout.concat "Hello world!" } + @output_buffer = '' + field_set_tag('') { @output_buffer.concat "Hello world!" } expected = %(<fieldset>Hello world!</fieldset>) - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end def protect_against_forgery? diff --git a/actionpack/test/template/javascript_helper_test.rb b/actionpack/test/template/javascript_helper_test.rb index f18adb990c..4924074c3e 100644 --- a/actionpack/test/template/javascript_helper_test.rb +++ b/actionpack/test/template/javascript_helper_test.rb @@ -82,8 +82,12 @@ class JavaScriptHelperTest < ActionView::TestCase end def test_javascript_tag + @output_buffer = 'foo' + assert_dom_equal "<script type=\"text/javascript\">\n//<![CDATA[\nalert('hello')\n//]]>\n</script>", javascript_tag("alert('hello')") + + assert_equal 'foo', @output_buffer, 'javascript_tag without a block should not concat to @output_buffer' end def test_javascript_tag_with_options @@ -92,15 +96,15 @@ class JavaScriptHelperTest < ActionView::TestCase end def test_javascript_tag_with_block - _erbout = '' - javascript_tag { _erbout.concat "alert('hello')" } - assert_dom_equal "<script type=\"text/javascript\">\n//<![CDATA[\nalert('hello')\n//]]>\n</script>", _erbout + @output_buffer = '' + javascript_tag { @output_buffer.concat "alert('hello')" } + assert_dom_equal "<script type=\"text/javascript\">\n//<![CDATA[\nalert('hello')\n//]]>\n</script>", @output_buffer end def test_javascript_tag_with_block_and_options - _erbout = '' - javascript_tag(:id => "the_js_tag") { _erbout.concat "alert('hello')" } - assert_dom_equal "<script id=\"the_js_tag\" type=\"text/javascript\">\n//<![CDATA[\nalert('hello')\n//]]>\n</script>", _erbout + @output_buffer = '' + javascript_tag(:id => "the_js_tag") { @output_buffer.concat "alert('hello')" } + assert_dom_equal "<script id=\"the_js_tag\" type=\"text/javascript\">\n//<![CDATA[\nalert('hello')\n//]]>\n</script>", @output_buffer end def test_javascript_cdata_section diff --git a/actionpack/test/template/prototype_helper_test.rb b/actionpack/test/template/prototype_helper_test.rb index b63d8a368c..3f5ec07214 100644 --- a/actionpack/test/template/prototype_helper_test.rb +++ b/actionpack/test/template/prototype_helper_test.rb @@ -118,52 +118,52 @@ class PrototypeHelperTest < PrototypeHelperBaseTest end def test_form_remote_tag_with_block - _erbout = '' - form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }) { _erbout.concat "Hello world!" } - assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\">Hello world!</form>), _erbout + @output_buffer = '' + form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }) { @output_buffer.concat "Hello world!" } + assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\">Hello world!</form>), @output_buffer end def test_remote_form_for_with_record_identification_with_new_record - _erbout = '' + @output_buffer = '' remote_form_for(@record, {:html => { :id => 'create-author' }}) {} expected = %(<form action='#{authors_path}' onsubmit="new Ajax.Request('#{authors_path}', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;" class='new_author' id='create-author' method='post'></form>) - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end def test_remote_form_for_with_record_identification_without_html_options - _erbout = '' + @output_buffer = '' remote_form_for(@record) {} expected = %(<form action='#{authors_path}' onsubmit="new Ajax.Request('#{authors_path}', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;" class='new_author' method='post' id='new_author'></form>) - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end def test_remote_form_for_with_record_identification_with_existing_record @record.save - _erbout = '' + @output_buffer = '' remote_form_for(@record) {} expected = %(<form action='#{author_path(@record)}' id='edit_author_1' method='post' onsubmit="new Ajax.Request('#{author_path(@record)}', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;" class='edit_author'><div style='margin:0;padding:0'><input name='_method' type='hidden' value='put' /></div></form>) - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end def test_remote_form_for_with_new_object_in_list - _erbout = '' + @output_buffer = '' remote_form_for([@author, @article]) {} expected = %(<form action='#{author_articles_path(@author)}' onsubmit="new Ajax.Request('#{author_articles_path(@author)}', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;" class='new_article' method='post' id='new_article'></form>) - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end def test_remote_form_for_with_existing_object_in_list @author.save @article.save - _erbout = '' + @output_buffer = '' remote_form_for([@author, @article]) {} expected = %(<form action='#{author_article_path(@author, @article)}' id='edit_article_1' method='post' onsubmit="new Ajax.Request('#{author_article_path(@author, @article)}', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;" class='edit_article'><div style='margin:0;padding:0'><input name='_method' type='hidden' value='put' /></div></form>) - assert_dom_equal expected, _erbout + assert_dom_equal expected, @output_buffer end def test_on_callbacks diff --git a/actionpack/test/template/record_tag_helper_test.rb b/actionpack/test/template/record_tag_helper_test.rb index 0afbb54f57..c39e5c69bf 100644 --- a/actionpack/test/template/record_tag_helper_test.rb +++ b/actionpack/test/template/record_tag_helper_test.rb @@ -17,37 +17,37 @@ class RecordTagHelperTest < ActionView::TestCase end def test_content_tag_for - _erbout = '' + @output_buffer = '' expected = %(<li class="post bar" id="post_45"></li>) actual = content_tag_for(:li, @post, :class => 'bar') { } assert_dom_equal expected, actual end def test_content_tag_for_prefix - _erbout = '' + @output_buffer = '' expected = %(<ul class="post" id="archived_post_45"></ul>) actual = content_tag_for(:ul, @post, :archived) { } assert_dom_equal expected, actual end def test_content_tag_for_with_extra_html_tags - _erbout = '' + @output_buffer = '' expected = %(<tr class="post bar" id="post_45" style='background-color: #f0f0f0'></tr>) actual = content_tag_for(:tr, @post, {:class => "bar", :style => "background-color: #f0f0f0"}) { } assert_dom_equal expected, actual end def test_block_works_with_content_tag_for - _erbout = '' + @output_buffer = '' expected = %(<tr class="post" id="post_45">#{@post.body}</tr>) - actual = content_tag_for(:tr, @post) { _erbout.concat @post.body } + actual = content_tag_for(:tr, @post) { @output_buffer.concat @post.body } assert_dom_equal expected, actual end def test_div_for - _erbout = '' + @output_buffer = '' expected = %(<div class="post bar" id="post_45">#{@post.body}</div>) - actual = div_for(@post, :class => "bar") { _erbout.concat @post.body } + actual = div_for(@post, :class => "bar") { @output_buffer.concat @post.body } assert_dom_equal expected, actual end diff --git a/actionpack/test/template/tag_helper_test.rb b/actionpack/test/template/tag_helper_test.rb index 4da6116095..7db04d178f 100644 --- a/actionpack/test/template/tag_helper_test.rb +++ b/actionpack/test/template/tag_helper_test.rb @@ -35,15 +35,15 @@ class TagHelperTest < ActionView::TestCase end def test_content_tag_with_block - _erbout = '' - content_tag(:div) { _erbout.concat "Hello world!" } - assert_dom_equal "<div>Hello world!</div>", _erbout + @output_buffer = '' + content_tag(:div) { @output_buffer.concat "Hello world!" } + assert_dom_equal "<div>Hello world!</div>", @output_buffer end def test_content_tag_with_block_and_options - _erbout = '' - content_tag(:div, :class => "green") { _erbout.concat "Hello world!" } - assert_dom_equal %(<div class="green">Hello world!</div>), _erbout + @output_buffer = '' + content_tag(:div, :class => "green") { @output_buffer.concat "Hello world!" } + assert_dom_equal %(<div class="green">Hello world!</div>), @output_buffer end def test_content_tag_with_block_and_options_outside_of_action_view diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb index 62cdca03d1..0f5c62acad 100644 --- a/actionpack/test/template/text_helper_test.rb +++ b/actionpack/test/template/text_helper_test.rb @@ -11,6 +11,14 @@ class TextHelperTest < ActionView::TestCase @_cycles = nil if (defined? @_cycles) end + def test_concat + @output_buffer = 'foo' + concat 'bar' + assert_equal 'foobar', @output_buffer + assert_nothing_raised { concat nil } + assert_equal 'foobar', @output_buffer + end + def test_simple_format assert_equal "<p></p>", simple_format(nil) |