diff options
Diffstat (limited to 'actionpack/test/template/form_helper_test.rb')
-rw-r--r-- | actionpack/test/template/form_helper_test.rb | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 0bfdbeebd1..2c60096475 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -735,11 +735,11 @@ class FormHelperTest < ActionView::TestCase 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 @@ -1230,6 +1230,27 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end + def test_nested_fields_for_arel_like + @post.comments = ArelLike.new + + form_for(@post) do |f| + concat f.text_field(:title) + concat f.fields_for(:comments, @post.comments) { |cf| + concat cf.text_field(:name) + } + end + + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do + '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' + + '<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" size="30" type="text" value="comment #1" />' + + '<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="1" />' + + '<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" size="30" type="text" value="comment #2" />' + + '<input id="post_comments_attributes_1_id" name="post[comments_attributes][1][id]" type="hidden" value="2" />' + end + + assert_dom_equal expected, output_buffer + end + def test_nested_fields_for_with_existing_records_on_a_supplied_nested_attributes_collection_different_from_record_one comments = Array.new(2) { |id| Comment.new(id + 1) } @post.comments = [] @@ -1528,17 +1549,20 @@ class FormHelperTest < ActionView::TestCase def snowman(method = nil) txt = %{<div style="margin:0;padding:0;display:inline">} txt << %{<input name="utf8" type="hidden" value="✓" />} - 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) @@ -1550,7 +1574,7 @@ class FormHelperTest < ActionView::TestCase 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 |