Ticket #10422: action_view_hidden_fields_tag_proc_no_inline_styles.diff
| File action_view_hidden_fields_tag_proc_no_inline_styles.diff, 11.0 kB (added by toolmantim, 7 months ago) |
|---|
-
actionpack/test/controller/request_forgery_protection_test.rb
old new 70 70 assert_select 'form>div>input[name=?][value=?]', 'authenticity_token', @token 71 71 end 72 72 73 def test_should_render_form_with_token_tag_inside_hidden_fields_tag_proc 74 default_proc = ActionView::Base.hidden_fields_tag_proc 75 ActionView::Base.hidden_fields_tag_proc = Proc.new {|fields| "<proctag>#{fields}</proctag>"} 76 get :index 77 assert_select 'form>proctag>input[name=?][value=?]', 'authenticity_token', @token 78 ensure 79 ActionView::Base.hidden_fields_tag_proc = default_proc 80 end 81 73 82 def test_should_render_button_to_with_token_tag 74 83 get :show_button 75 84 assert_select 'form>div>input[name=?][value=?]', 'authenticity_token', @token 76 85 end 77 86 78 87 def test_should_allow_get 79 88 get :index 80 89 assert_response :success -
actionpack/test/template/form_tag_helper_test.rb
old new 36 36 37 37 def test_form_tag_with_method_put 38 38 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><input type="hidden" name="_method" value="put" /></div>) 40 40 assert_dom_equal expected, actual 41 41 end 42 42 43 43 def test_form_tag_with_method_delete 44 44 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><input type="hidden" name="_method" value="delete" /></div>) 46 46 assert_dom_equal expected, actual 47 47 end 48 49 def test_form_tag_with_method_put_with_custom_hidden_fields_tag_proc 50 default_proc = ActionView::Base.hidden_fields_tag_proc 51 ActionView::Base.hidden_fields_tag_proc = Proc.new {|fields| "<proctag>#{fields}</proctag>"} 52 actual = form_tag({}, { :method => :put }) 53 expected = %(<form action="http://www.example.com" method="post"><proctag><input type="hidden" name="_method" value="put" /></proctag>) 54 assert_dom_equal expected, actual 55 ensure 56 ActionView::Base.hidden_fields_tag_proc = default_proc 57 end 48 58 59 def test_form_tag_with_method_delete_with_custom_hidden_fields_tag_proc 60 default_proc = ActionView::Base.hidden_fields_tag_proc 61 ActionView::Base.hidden_fields_tag_proc = Proc.new {|fields| "<proctag>#{fields}</proctag>"} 62 actual = form_tag({}, { :method => :delete }) 63 expected = %(<form action="http://www.example.com" method="post"><proctag><input type="hidden" name="_method" value="delete" /></proctag>) 64 assert_dom_equal expected, actual 65 ensure 66 ActionView::Base.hidden_fields_tag_proc = default_proc 67 end 68 49 69 def test_form_tag_with_block 50 70 _erbout = '' 51 71 form_tag("http://example.com") { _erbout.concat "Hello world!" } … … 58 78 _erbout = '' 59 79 form_tag("http://example.com", :method => :put) { _erbout.concat "Hello world!" } 60 80 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>)81 expected = %(<form action="http://example.com" method="post"><div><input type="hidden" name="_method" value="put" /></div>Hello world!</form>) 62 82 assert_dom_equal expected, _erbout 63 83 end 64 84 -
actionpack/test/template/form_helper_test.rb
old new 331 331 332 332 expected = 333 333 "<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><input name='_method' type='hidden' value='put' /></div>" + 335 335 "<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" + 336 336 "<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" + 337 337 "<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" + … … 682 682 683 683 form_for(@post) do |f| end 684 684 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><input name=\"_method\" type=\"hidden\" value=\"put\" /></div></form>" 686 686 assert_equal expected, _erbout 687 687 end 688 688 … … 705 705 _erbout = '' 706 706 form_for([@post, @comment]) {} 707 707 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><input name="_method" type="hidden" value="put" /></div></form>) 709 709 assert_dom_equal expected, _erbout 710 710 end 711 711 … … 724 724 _erbout = '' 725 725 form_for([:admin, @post, @comment]) {} 726 726 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><input name="_method" type="hidden" value="put" /></div></form>) 728 728 assert_dom_equal expected, _erbout 729 729 end 730 730 … … 742 742 743 743 form_for(@post, :url => "/super_posts") do |f| end 744 744 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><input name=\"_method\" type=\"hidden\" value=\"put\" /></div></form>" 746 746 assert_equal expected, _erbout 747 747 end 748 748 -
actionpack/test/template/prototype_helper_test.rb
old new 126 126 end 127 127 128 128 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><input name='_method' type='hidden' value='put' /></div>), 130 130 form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }, :html => { :method => :put }) 131 131 end 132 132 … … 157 157 _erbout = '' 158 158 remote_form_for(@record) {} 159 159 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><input name='_method' type='hidden' value='put' /></div></form>) 161 161 assert_dom_equal expected, _erbout 162 162 end 163 163 … … 175 175 _erbout = '' 176 176 remote_form_for([@author, @article]) {} 177 177 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><input name='_method' type='hidden' value='put' /></div></form>) 179 179 assert_dom_equal expected, _erbout 180 180 end 181 181 -
actionpack/lib/action_view/helpers/form_tag_helper.rb
old new 2 2 require 'action_view/helpers/tag_helper' 3 3 4 4 module ActionView 5 class Base 6 # Specify the proc used to surround hidden form fields with a block level element. 7 # 8 # Defaults to: 9 # Proc.new{|fields| "<div>#{fields}</div>"} 10 @@hidden_fields_tag_proc = Proc.new{|fields| "<div>#{fields}</div>"} 11 cattr_accessor :hidden_fields_tag_proc 12 end 5 13 module Helpers 6 14 # Provides a number of methods for creating form tags that doesn't rely on an ActiveRecord object assigned to the template like 7 15 # FormHelper does. Instead, you provide the names and values manually. … … 401 409 '' 402 410 when /^post$/i, "", nil 403 411 html_options["method"] = "post" 404 protect_against_forgery? ? content_tag(:div, token_tag, :style => 'margin:0;padding:0') : ''412 protect_against_forgery? ? Base.hidden_fields_tag_proc.call(token_tag) : '' 405 413 else 406 414 html_options["method"] = "post" 407 content_tag(:div, tag(:input, :type => "hidden", :name => "_method", :value => method) + token_tag, :style => 'margin:0;padding:0')415 Base.hidden_fields_tag_proc.call(tag(:input, :type => "hidden", :name => "_method", :value => method) + token_tag) 408 416 end 409 417 end 410 418