Skip to content

Commit

Permalink
Fix test helpers to ensure get method forms are properly tested [#5753
Browse files Browse the repository at this point in the history
…state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
Aditya Sanghi authored and josevalim committed Oct 11, 2010
1 parent 3eff729 commit 582a088
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
15 changes: 9 additions & 6 deletions actionpack/test/template/form_helper_test.rb
Expand Up @@ -735,11 +735,11 @@ def test_form_for_with_method
def test_form_for_with_search_field
# Test case for bug which would emit an "object" attribute
# when used with form_for using a search_field form helper
form_for(Post.new, :url => "/search", :html => { :id => 'search-post' }) do |f|
form_for(Post.new, :url => "/search", :html => { :id => 'search-post', :method => :get}) do |f|
concat f.search_field(:title)
end

expected = whole_form("/search", "search-post", "new_post") do
expected = whole_form("/search", "search-post", "new_post", "get") do
"<input name='post[title]' size='30' type='search' id='post_title' />"
end

Expand Down Expand Up @@ -1528,17 +1528,20 @@ def test_form_for_with_labelled_builder
def snowman(method = nil)
txt = %{<div style="margin:0;padding:0;display:inline">}
txt << %{<input name="utf8" type="hidden" value="&#x2713;" />}
txt << %{<input name="_method" type="hidden" value="#{method}" />} if method
if (method && !['get','post'].include?(method.to_s))
txt << %{<input name="_method" type="hidden" value="#{method}" />}
end
txt << %{</div>}
end

def form_text(action = "/", id = nil, html_class = nil, remote = nil, multipart = nil)
def form_text(action = "/", id = nil, html_class = nil, remote = nil, multipart = nil, method = nil)
txt = %{<form accept-charset="UTF-8" action="#{action}"}
txt << %{ enctype="multipart/form-data"} if multipart
txt << %{ data-remote="true"} if remote
txt << %{ class="#{html_class}"} if html_class
txt << %{ id="#{id}"} if id
txt << %{ method="post">}
method = method.to_s == "get" ? "get" : "post"
txt << %{ method="#{method}">}
end

def whole_form(action = "/", id = nil, html_class = nil, options = nil)
Expand All @@ -1550,7 +1553,7 @@ def whole_form(action = "/", id = nil, html_class = nil, options = nil)
method = options
end

form_text(action, id, html_class, remote, multipart) + snowman(method) + contents + "</form>"
form_text(action, id, html_class, remote, multipart, method) + snowman(method) + contents + "</form>"
end

def test_default_form_builder
Expand Down
10 changes: 7 additions & 3 deletions actionpack/test/template/form_tag_helper_test.rb
Expand Up @@ -13,19 +13,23 @@ def snowman(options = {})

txt = %{<div style="margin:0;padding:0;display:inline">}
txt << %{<input name="utf8" type="hidden" value="&#x2713;" />}
txt << %{<input name="_method" type="hidden" value="#{method}" />} if method
if (method && !['get','post'].include?(method.to_s))
txt << %{<input name="_method" type="hidden" value="#{method}" />}
end
txt << %{</div>}
end

def form_text(action = "http://www.example.com", options = {})
remote, enctype, html_class, id = options.values_at(:remote, :enctype, :html_class, :id)
remote, enctype, html_class, id, method = options.values_at(:remote, :enctype, :html_class, :id, :method)

method = method.to_s == "get" ? "get" : "post"

txt = %{<form accept-charset="UTF-8" action="#{action}"}
txt << %{ enctype="multipart/form-data"} if enctype
txt << %{ data-remote="true"} if remote
txt << %{ class="#{html_class}"} if html_class
txt << %{ id="#{id}"} if id
txt << %{ method="post">}
txt << %{ method="#{method}">}
end

def whole_form(action = "http://www.example.com", options = {})
Expand Down

0 comments on commit 582a088

Please sign in to comment.