Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #10422: action_view_hidden_fields_tag_proc_no_inline_styles_no_config_with_clas.diff

File action_view_hidden_fields_tag_proc_no_inline_styles_no_config_with_clas.diff, 10.4 kB (added by toolmantim, 6 months ago)

Patch that removes inline styles and replaces with a simple "hidden-fields" class

  • actionpack/test/template/form_tag_helper_test.rb

    old new  
    3636 
    3737  def test_form_tag_with_method_put 
    3838    actual = form_tag({}, { :method => :put }) 
    39     expected = %(<form action="http://www.example.com" method="post"><div style='margin:0;padding:0'><input type="hidden" name="_method" value="put" /></div>) 
     39    expected = %(<form action="http://www.example.com" method="post"><div class="hidden-fields"><input type="hidden" name="_method" value="put" /></div>) 
    4040    assert_dom_equal expected, actual 
    4141  end 
    4242   
    4343  def test_form_tag_with_method_delete 
    4444    actual = form_tag({}, { :method => :delete }) 
    45     expected = %(<form action="http://www.example.com" method="post"><div style='margin:0;padding:0'><input type="hidden" name="_method" value="delete" /></div>) 
     45    expected = %(<form action="http://www.example.com" method="post"><div class="hidden-fields"><input type="hidden" name="_method" value="delete" /></div>) 
    4646    assert_dom_equal expected, actual 
    4747  end 
    48  
     48   
    4949  def test_form_tag_with_block 
    5050    _erbout = '' 
    5151    form_tag("http://example.com") { _erbout.concat "Hello world!" } 
     
    5858    _erbout = '' 
    5959    form_tag("http://example.com", :method => :put) { _erbout.concat "Hello world!" } 
    6060 
    61     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>) 
     61    expected = %(<form action="http://example.com" method="post"><div class="hidden-fields"><input type="hidden" name="_method" value="put" /></div>Hello world!</form>) 
    6262    assert_dom_equal expected, _erbout 
    6363  end 
    6464 
  • actionpack/test/template/form_helper_test.rb

    old new  
    331331 
    332332    expected =  
    333333      "<form action='http://www.example.com' id='create-post' method='post'>" + 
    334       "<div style='margin:0;padding:0'><input name='_method' type='hidden' value='put' /></div>" + 
     334      "<div class='hidden-fields'><input name='_method' type='hidden' value='put' /></div>" + 
    335335      "<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" + 
    336336      "<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" + 
    337337      "<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" + 
     
    682682 
    683683    form_for(@post) do |f| end 
    684684 
    685     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>" 
     685    expected = "<form action=\"/posts/123\" class=\"edit_post\" id=\"edit_post_123\" method=\"post\"><div class=\"hidden-fields\"><input name=\"_method\" type=\"hidden\" value=\"put\" /></div></form>" 
    686686    assert_equal expected, _erbout 
    687687  end 
    688688 
     
    705705    _erbout = '' 
    706706    form_for([@post, @comment]) {} 
    707707 
    708     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>) 
     708    expected = %(<form action="#{comment_path(@post, @comment)}" class="edit_comment" id="edit_comment_1" method="post"><div class="hidden-fields"><input name="_method" type="hidden" value="put" /></div></form>) 
    709709    assert_dom_equal expected, _erbout 
    710710  end 
    711711 
     
    724724    _erbout = '' 
    725725    form_for([:admin, @post, @comment]) {} 
    726726   
    727     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>) 
     727    expected = %(<form action="#{admin_comment_path(@post, @comment)}" class="edit_comment" id="edit_comment_1" method="post"><div class="hidden-fields"><input name="_method" type="hidden" value="put" /></div></form>) 
    728728    assert_dom_equal expected, _erbout 
    729729  end 
    730730   
     
    742742 
    743743    form_for(@post, :url => "/super_posts") do |f| end 
    744744 
    745     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>" 
     745    expected = "<form action=\"/super_posts\" class=\"edit_post\" id=\"edit_post_123\" method=\"post\"><div class=\"hidden-fields\"><input name=\"_method\" type=\"hidden\" value=\"put\" /></div></form>" 
    746746    assert_equal expected, _erbout 
    747747  end 
    748748 
  • actionpack/test/template/prototype_helper_test.rb

    old new  
    126126  end 
    127127 
    128128  def test_form_remote_tag_with_method 
    129     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;\"><div style='margin:0;padding:0'><input name='_method' type='hidden' value='put' /></div>), 
     129    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;\"><div class='hidden-fields'><input name='_method' type='hidden' value='put' /></div>), 
    130130      form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast  }, :html => { :method => :put }) 
    131131  end 
    132132 
     
    157157    _erbout = '' 
    158158    remote_form_for(@record) {} 
    159159     
    160     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>) 
     160    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 class='hidden-fields'><input name='_method' type='hidden' value='put' /></div></form>) 
    161161    assert_dom_equal expected, _erbout 
    162162  end 
    163163 
     
    175175    _erbout = '' 
    176176    remote_form_for([@author, @article]) {} 
    177177     
    178     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>) 
     178    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 class='hidden-fields'><input name='_method' type='hidden' value='put' /></div></form>) 
    179179    assert_dom_equal expected, _erbout 
    180180  end 
    181181 
  • actionpack/test/template/active_record_helper_test.rb

    old new  
    151151    @request_forgery_protection_token = 'authenticity_token' 
    152152    @form_authenticity_token = '123' 
    153153    assert_dom_equal( 
    154       %(<form action="create" method="post"><div style='margin:0;padding:0'><input type='hidden' name='authenticity_token' value='123' /></div><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>), 
     154      %(<form action="create" method="post"><div class="hidden-fields"><input type='hidden' name='authenticity_token' value='123' /></div><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>), 
    155155      form("post") 
    156156    ) 
    157157  end 
  • actionpack/lib/action_view/helpers/form_tag_helper.rb

    old new  
    401401              '' 
    402402            when /^post$/i, "", nil 
    403403              html_options["method"] = "post" 
    404               protect_against_forgery? ? content_tag(:div, token_tag, :style => 'margin:0;padding:0') : '' 
     404              # Surround with div for (x)html strict compliance 
     405              protect_against_forgery? ? extra_form_tags_div(token_tag) : '' 
    405406            else 
    406407              html_options["method"] = "post" 
    407               content_tag(:div, tag(:input, :type => "hidden", :name => "_method", :value => method) + token_tag, :style => 'margin:0;padding:0') 
     408              # Surround with div for (x)html strict compliance 
     409              extra_form_tags_div(tag(:input, :type => "hidden", :name => "_method", :value => method) + token_tag) 
    408410          end 
    409411        end 
    410412         
     413        def extra_form_tags_div(content) 
     414          content_tag(:div, content, :class => "hidden-fields") 
     415        end 
     416         
    411417        def form_tag_html(html_options) 
    412418          extra_tags = extra_tags_for_form(html_options) 
    413419          tag(:form, html_options, true) + extra_tags