Review most of the form_for deprecated tests, missing tests with index like []

This commit is contained in:
Carlos Antonio da Silva 2010-09-25 22:49:46 +08:00 committed by José Valim
parent 7fc1edd790
commit 8a16485a96
2 changed files with 322 additions and 405 deletions

View File

@ -91,6 +91,7 @@ class Comment
attr_accessor :relevances
def relevances_attributes=(attributes); end
attr_accessor :body
end
class Tag

View File

@ -647,26 +647,22 @@ class FormHelperTest < ActionView::TestCase
end
def test_form_for
assert_deprecated do
form_for(:post, @post, :html => { :id => 'create-post' }) do |f|
form_for(@post, :html => { :id => 'create-post' }) do |f|
concat f.label(:title) { "The Title" }
concat f.text_field(:title)
concat f.text_area(:body)
concat f.check_box(:secret)
concat f.submit('Create post')
end
end
expected =
"<form accept-charset='UTF-8' action='/' id='create-post' method='post'>" +
snowman +
expected = whole_form("/posts/123", "create-post" , "edit_post", :method => "put") do
"<label for='post_title'>The Title</label>" +
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
"<input name='post[secret]' type='hidden' value='0' />" +
"<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
"<input name='commit' id='post_submit' type='submit' value='Create post' />" +
"</form>"
"<input name='commit' id='post_submit' type='submit' value='Create post' />"
end
assert_dom_equal expected, output_buffer
end
@ -674,17 +670,13 @@ class FormHelperTest < ActionView::TestCase
def test_form_for_with_file_field_generate_multipart
Post.send :attr_accessor, :file
assert_deprecated do
form_for(:post, @post, :html => { :id => 'create-post' }) do |f|
form_for(@post, :html => { :id => 'create-post' }) do |f|
concat f.file_field(:file)
end
end
expected =
"<form accept-charset='UTF-8' action='/' id='create-post' method='post' enctype='multipart/form-data'>" +
snowman +
"<input name='post[file]' type='file' id='post_file' />" +
"</form>"
expected = whole_form("/posts/123", "create-post" , "edit_post", :method => "put", :multipart => true) do
"<input name='post[file]' type='file' id='post_file' />"
end
assert_dom_equal expected, output_buffer
end
@ -692,19 +684,15 @@ class FormHelperTest < ActionView::TestCase
def test_fields_for_with_file_field_generate_multipart
Comment.send :attr_accessor, :file
assert_deprecated do
form_for(:post, @post) do |f|
form_for(@post) do |f|
concat f.fields_for(:comment, @post) { |c|
concat c.file_field(:file)
}
end
end
expected =
"<form accept-charset='UTF-8' action='/' method='post' enctype='multipart/form-data'>" +
snowman +
"<input name='post[comment][file]' type='file' id='post_comment_file' />" +
"</form>"
expected = whole_form("/posts/123", "edit_post_123" , "edit_post", :method => "put", :multipart => true) do
"<input name='post[comment][file]' type='file' id='post_comment_file' />"
end
assert_dom_equal expected, output_buffer
end
@ -759,15 +747,13 @@ class FormHelperTest < ActionView::TestCase
end
def test_form_for_with_method
assert_deprecated do
form_for(:post, @post, :html => { :id => 'create-post', :method => :put }) do |f|
form_for(@post, :url => '/', :html => { :id => 'create-post', :method => :put }) do |f|
concat f.text_field(:title)
concat f.text_area(:body)
concat f.check_box(:secret)
end
end
expected = whole_form("/", "create-post", nil, "put") do
expected = whole_form("/", "create-post", "edit_post", "put") do
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
"<input name='post[secret]' type='hidden' value='0' />" +
@ -778,15 +764,13 @@ class FormHelperTest < ActionView::TestCase
end
def test_form_for_with_remote
assert_deprecated do
form_for(:post, @post, :remote => true, :html => { :id => 'create-post', :method => :put }) do |f|
form_for(@post, :url => '/', :remote => true, :html => { :id => 'create-post', :method => :put }) do |f|
concat f.text_field(:title)
concat f.text_area(:body)
concat f.check_box(:secret)
end
end
expected = whole_form("/", "create-post", nil, :method => "put", :remote => true) do
expected = whole_form("/", "create-post", "edit_post", :method => "put", :remote => true) do
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
"<input name='post[secret]' type='hidden' value='0' />" +
@ -797,15 +781,14 @@ class FormHelperTest < ActionView::TestCase
end
def test_form_for_with_remote_without_html
assert_deprecated do
form_for(:post, @post, :remote => true) do |f|
@post.persisted = false
form_for(@post, :remote => true) do |f|
concat f.text_field(:title)
concat f.text_area(:body)
concat f.check_box(:secret)
end
end
expected = whole_form("/", nil, nil, :remote => true) do
expected = whole_form("/posts", 'new_post', 'new_post', :remote => true) do
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
"<input name='post[secret]' type='hidden' value='0' />" +
@ -876,13 +859,11 @@ class FormHelperTest < ActionView::TestCase
old_locale, I18n.locale = I18n.locale, :submit
@post.persisted = false
assert_deprecated do
form_for(:post, @post) do |f|
form_for(@post) do |f|
concat f.submit
end
end
expected = whole_form do
expected = whole_form('/posts', 'new_post', 'new_post') do
"<input name='commit' id='post_submit' type='submit' value='Create Post' />"
end
@ -894,13 +875,11 @@ class FormHelperTest < ActionView::TestCase
def test_submit_with_object_as_existing_record_and_locale_strings
old_locale, I18n.locale = I18n.locale, :submit
assert_deprecated do
form_for(:post, @post) do |f|
form_for(@post) do |f|
concat f.submit
end
end
expected = whole_form do
expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do
"<input name='commit' id='post_submit' type='submit' value='Confirm Post changes' />"
end
@ -928,13 +907,11 @@ class FormHelperTest < ActionView::TestCase
def test_submit_with_object_and_nested_lookup
old_locale, I18n.locale = I18n.locale, :submit
assert_deprecated do
form_for(:another_post, @post) do |f|
form_for(@post, :as => :another_post) do |f|
concat f.submit
end
end
expected = whole_form do
expected = whole_form('/posts/123', 'another_post_edit', 'another_post_edit', :method => 'put') do
"<input name='commit' id='another_post_submit' type='submit' value='Update your Post' />"
end
@ -944,16 +921,15 @@ class FormHelperTest < ActionView::TestCase
end
def test_nested_fields_for
assert_deprecated do
form_for(:post, @post) do |f|
concat f.fields_for(:comment, @post) { |c|
concat c.text_field(:title)
@comment.body = 'Hello World'
form_for(@post) do |f|
concat f.fields_for(@comment) { |c|
concat c.text_field(:body)
}
end
end
expected = whole_form do
"<input name='post[comment][title]' size='30' type='text' id='post_comment_title' value='Hello World' />"
expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do
"<input name='post[comment][body]' size='30' type='text' id='post_comment_body' value='Hello World' />"
end
assert_dom_equal expected, output_buffer
@ -996,15 +972,13 @@ class FormHelperTest < ActionView::TestCase
end
def test_form_for_with_index_and_nested_fields_for
assert_deprecated do
output_buffer = form_for(:post, @post, :index => 1) do |f|
output_buffer = form_for(@post, :index => 1) do |f|
concat f.fields_for(:comment, @post) { |c|
concat c.text_field(:title)
}
end
end
expected = whole_form do
expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', 'put') do
"<input name='post[1][comment][title]' size='30' type='text' id='post_1_comment_title' value='Hello World' />"
end
@ -1012,15 +986,13 @@ class FormHelperTest < ActionView::TestCase
end
def test_nested_fields_for_with_index_on_both
assert_deprecated do
form_for(:post, @post, :index => 1) do |f|
form_for(@post, :index => 1) do |f|
concat f.fields_for(:comment, @post, :index => 5) { |c|
concat c.text_field(:title)
}
end
end
expected = whole_form do
expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', 'put') do
"<input name='post[1][comment][5][title]' size='30' type='text' id='post_1_comment_5_title' value='Hello World' />"
end
@ -1044,15 +1016,13 @@ class FormHelperTest < ActionView::TestCase
end
def test_nested_fields_for_with_index_radio_button
assert_deprecated do
form_for(:post, @post) do |f|
form_for(@post) do |f|
concat f.fields_for(:comment, @post, :index => 5) { |c|
concat c.radio_button(:title, "hello")
}
end
end
expected = whole_form do
expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', 'put') do
"<input name='post[comment][5][title]' type='radio' id='post_comment_5_title_hello' value='hello' />"
end
@ -1102,16 +1072,14 @@ class FormHelperTest < ActionView::TestCase
def test_nested_fields_for_with_a_new_record_on_a_nested_attributes_one_to_one_association
@post.author = Author.new
assert_deprecated do
form_for(:post, @post) do |f|
form_for(@post) do |f|
concat f.text_field(:title)
concat f.fields_for(:author) { |af|
concat af.text_field(:name)
}
end
end
expected = whole_form do
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_author_attributes_name" name="post[author_attributes][name]" size="30" type="text" value="new author" />'
end
@ -1120,29 +1088,25 @@ class FormHelperTest < ActionView::TestCase
end
def test_nested_fields_for_with_explicitly_passed_object_on_a_nested_attributes_one_to_one_association
assert_deprecated do
form_for(:post, @post) do |f|
form_for(@post) do |f|
f.fields_for(:author, Author.new(123)) do |af|
assert_not_nil af.object
assert_equal 123, af.object.id
end
end
end
end
def test_nested_fields_for_with_an_existing_record_on_a_nested_attributes_one_to_one_association
@post.author = Author.new(321)
assert_deprecated do
form_for(:post, @post) do |f|
form_for(@post) do |f|
concat f.text_field(:title)
concat f.fields_for(:author) { |af|
concat af.text_field(:name)
}
end
end
expected = whole_form do
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_author_attributes_name" name="post[author_attributes][name]" size="30" type="text" value="author #321" />' +
'<input id="post_author_attributes_id" name="post[author_attributes][id]" type="hidden" value="321" />'
@ -1154,17 +1118,15 @@ class FormHelperTest < ActionView::TestCase
def test_nested_fields_for_with_existing_records_on_a_nested_attributes_one_to_one_association_with_explicit_hidden_field_placement
@post.author = Author.new(321)
assert_deprecated do
form_for(:post, @post) do |f|
form_for(@post) do |f|
concat f.text_field(:title)
concat f.fields_for(:author) { |af|
concat af.hidden_field(:id)
concat af.text_field(:name)
}
end
end
expected = whole_form do
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_author_attributes_id" name="post[author_attributes][id]" type="hidden" value="321" />' +
'<input id="post_author_attributes_name" name="post[author_attributes][name]" size="30" type="text" value="author #321" />'
@ -1176,8 +1138,7 @@ class FormHelperTest < ActionView::TestCase
def test_nested_fields_for_with_existing_records_on_a_nested_attributes_collection_association
@post.comments = Array.new(2) { |id| Comment.new(id + 1) }
assert_deprecated do
form_for(:post, @post) do |f|
form_for(@post) do |f|
concat f.text_field(:title)
@post.comments.each do |comment|
concat f.fields_for(:comments, comment) { |cf|
@ -1185,9 +1146,8 @@ class FormHelperTest < ActionView::TestCase
}
end
end
end
expected = whole_form do
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" />' +
@ -1201,8 +1161,7 @@ class FormHelperTest < ActionView::TestCase
def test_nested_fields_for_with_existing_records_on_a_nested_attributes_collection_association_with_explicit_hidden_field_placement
@post.comments = Array.new(2) { |id| Comment.new(id + 1) }
assert_deprecated do
form_for(:post, @post) do |f|
form_for(@post) do |f|
concat f.text_field(:title)
@post.comments.each do |comment|
concat f.fields_for(:comments, comment) { |cf|
@ -1211,9 +1170,8 @@ class FormHelperTest < ActionView::TestCase
}
end
end
end
expected = whole_form do
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_id" name="post[comments_attributes][0][id]" type="hidden" value="1" />' +
'<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" size="30" type="text" value="comment #1" />' +
@ -1227,8 +1185,7 @@ class FormHelperTest < ActionView::TestCase
def test_nested_fields_for_with_new_records_on_a_nested_attributes_collection_association
@post.comments = [Comment.new, Comment.new]
assert_deprecated do
form_for(:post, @post) do |f|
form_for(@post) do |f|
concat f.text_field(:title)
@post.comments.each do |comment|
concat f.fields_for(:comments, comment) { |cf|
@ -1236,9 +1193,8 @@ class FormHelperTest < ActionView::TestCase
}
end
end
end
expected = whole_form do
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="new comment" />' +
'<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" size="30" type="text" value="new comment" />'
@ -1250,8 +1206,7 @@ class FormHelperTest < ActionView::TestCase
def test_nested_fields_for_with_existing_and_new_records_on_a_nested_attributes_collection_association
@post.comments = [Comment.new(321), Comment.new]
assert_deprecated do
form_for(:post, @post) do |f|
form_for(@post) do |f|
concat f.text_field(:title)
@post.comments.each do |comment|
concat f.fields_for(:comments, comment) { |cf|
@ -1259,9 +1214,8 @@ class FormHelperTest < ActionView::TestCase
}
end
end
end
expected = whole_form do
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 #321" />' +
'<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="321" />' +
@ -1272,16 +1226,14 @@ class FormHelperTest < ActionView::TestCase
end
def test_nested_fields_for_with_an_empty_supplied_attributes_collection
assert_deprecated do
form_for(:post, @post) do |f|
form_for(@post) do |f|
concat f.text_field(:title)
f.fields_for(:comments, []) do |cf|
concat cf.text_field(:name)
end
end
end
expected = whole_form do
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" />'
end
@ -1291,16 +1243,14 @@ class FormHelperTest < ActionView::TestCase
def test_nested_fields_for_with_existing_records_on_a_supplied_nested_attributes_collection
@post.comments = Array.new(2) { |id| Comment.new(id + 1) }
assert_deprecated do
form_for(:post, @post) do |f|
form_for(@post) do |f|
concat f.text_field(:title)
concat f.fields_for(:comments, @post.comments) { |cf|
concat cf.text_field(:name)
}
end
end
expected = whole_form do
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" />' +
@ -1315,16 +1265,14 @@ class FormHelperTest < ActionView::TestCase
comments = Array.new(2) { |id| Comment.new(id + 1) }
@post.comments = []
assert_deprecated do
form_for(:post, @post) do |f|
form_for(@post) do |f|
concat f.text_field(:title)
concat f.fields_for(:comments, comments) { |cf|
concat cf.text_field(:name)
}
end
end
expected = whole_form do
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" />' +
@ -1339,17 +1287,15 @@ class FormHelperTest < ActionView::TestCase
@post.comments = [Comment.new(321), Comment.new]
yielded_comments = []
assert_deprecated do
form_for(:post, @post) do |f|
form_for(@post) do |f|
concat f.text_field(:title)
concat f.fields_for(:comments) { |cf|
concat cf.text_field(:name)
yielded_comments << cf.object
}
end
end
expected = whole_form do
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 #321" />' +
'<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="321" />' +
@ -1363,15 +1309,13 @@ class FormHelperTest < ActionView::TestCase
def test_nested_fields_for_with_child_index_option_override_on_a_nested_attributes_collection_association
@post.comments = []
assert_deprecated do
form_for(:post, @post) do |f|
form_for(@post) do |f|
concat f.fields_for(:comments, Comment.new(321), :child_index => 'abc') { |cf|
concat cf.text_field(:name)
}
end
end
expected = whole_form do
expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do
'<input id="post_comments_attributes_abc_name" name="post[comments_attributes][abc][name]" size="30" type="text" value="comment #321" />' +
'<input id="post_comments_attributes_abc_id" name="post[comments_attributes][abc][id]" type="hidden" value="321" />'
end
@ -1386,8 +1330,7 @@ class FormHelperTest < ActionView::TestCase
@post.tags[0].relevances = []
@post.tags[1].relevances = []
assert_deprecated do
form_for(:post, @post) do |f|
form_for(@post) do |f|
concat f.fields_for(:comments, @post.comments[0]) { |cf|
concat cf.text_field(:name)
concat cf.fields_for(:relevances, CommentRelevance.new(314)) { |crf|
@ -1407,9 +1350,8 @@ class FormHelperTest < ActionView::TestCase
}
}
end
end
expected = whole_form do
expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do
'<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" size="30" type="text" value="comment #321" />' +
'<input id="post_comments_attributes_0_relevances_attributes_0_value" name="post[comments_attributes][0][relevances_attributes][0][value]" size="30" type="text" value="commentrelevance #314" />' +
'<input id="post_comments_attributes_0_relevances_attributes_0_id" name="post[comments_attributes][0][relevances_attributes][0][id]" type="hidden" value="314" />' +
@ -1550,8 +1492,7 @@ class FormHelperTest < ActionView::TestCase
end
def test_form_for_and_fields_for
assert_deprecated do
form_for(:post, @post, :html => { :id => 'create-post' }) do |post_form|
form_for(@post, :as => :post, :html => { :id => 'create-post' }) do |post_form|
concat post_form.text_field(:title)
concat post_form.text_area(:body)
@ -1559,23 +1500,19 @@ class FormHelperTest < ActionView::TestCase
concat parent_fields.check_box(:secret)
}
end
end
expected =
"<form accept-charset='UTF-8' action='/' id='create-post' method='post'>" +
snowman +
expected = whole_form('/posts/123', 'create-post', 'post_edit', :method => 'put') do
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
"<input name='parent_post[secret]' type='hidden' value='0' />" +
"<input name='parent_post[secret]' checked='checked' type='checkbox' id='parent_post_secret' value='1' />" +
"</form>"
"<input name='parent_post[secret]' checked='checked' type='checkbox' id='parent_post_secret' value='1' />"
end
assert_dom_equal expected, output_buffer
end
def test_form_for_and_fields_for_with_object
assert_deprecated do
form_for(:post, @post, :html => { :id => 'create-post' }) do |post_form|
form_for(@post, :as => :post, :html => { :id => 'create-post' }) do |post_form|
concat post_form.text_field(:title)
concat post_form.text_area(:body)
@ -1583,10 +1520,8 @@ class FormHelperTest < ActionView::TestCase
concat comment_fields.text_field(:name)
}
end
end
expected =
whole_form("/", "create-post") do
expected = whole_form('/posts/123', 'create-post', 'post_edit', :method => 'put') do
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
"<input name='post[comment][name]' type='text' id='post_comment_name' value='new comment' size='30' />"
@ -1606,15 +1541,13 @@ class FormHelperTest < ActionView::TestCase
end
def test_form_for_with_labelled_builder
assert_deprecated do
form_for(:post, @post, :builder => LabelledFormBuilder) do |f|
form_for(@post, :builder => LabelledFormBuilder) do |f|
concat f.text_field(:title)
concat f.text_area(:body)
concat f.check_box(:secret)
end
end
expected = whole_form do
expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do
"<label for='title'>Title:</label> <input name='post[title]' size='30' type='text' id='post_title' value='Hello World' /><br/>" +
"<label for='body'>Body:</label> <textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea><br/>" +
"<label for='secret'>Secret:</label> <input name='post[secret]' type='hidden' value='0' /><input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' /><br/>"
@ -1630,8 +1563,9 @@ class FormHelperTest < ActionView::TestCase
txt << %{</div>}
end
def form_text(action = "/", id = nil, html_class = nil, remote = nil)
def form_text(action = "/", id = nil, html_class = nil, remote = nil, multipart = 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
@ -1642,27 +1576,25 @@ class FormHelperTest < ActionView::TestCase
contents = block_given? ? yield : ""
if options.is_a?(Hash)
method, remote = options.values_at(:method, :remote)
method, remote, multipart = options.values_at(:method, :remote, :multipart)
else
method = options
end
form_text(action, id, html_class, remote) + snowman(method) + contents + "</form>"
form_text(action, id, html_class, remote, multipart) + snowman(method) + contents + "</form>"
end
def test_default_form_builder
old_default_form_builder, ActionView::Base.default_form_builder =
ActionView::Base.default_form_builder, LabelledFormBuilder
assert_deprecated do
form_for(:post, @post) do |f|
form_for(@post) do |f|
concat f.text_field(:title)
concat f.text_area(:body)
concat f.check_box(:secret)
end
end
expected = whole_form do
expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do
"<label for='title'>Title:</label> <input name='post[title]' size='30' type='text' id='post_title' value='Hello World' /><br/>" +
"<label for='body'>Body:</label> <textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea><br/>" +
"<label for='secret'>Secret:</label> <input name='post[secret]' type='hidden' value='0' /><input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' /><br/>"
@ -1691,14 +1623,12 @@ class FormHelperTest < ActionView::TestCase
def test_form_for_with_labelled_builder_with_nested_fields_for_without_options_hash
klass = nil
assert_deprecated do
form_for(:post, @post, :builder => LabelledFormBuilder) do |f|
form_for(@post, :builder => LabelledFormBuilder) do |f|
f.fields_for(:comments, Comment.new) do |nested_fields|
klass = nested_fields.class
''
end
end
end
assert_equal LabelledFormBuilder, klass
end
@ -1706,14 +1636,12 @@ class FormHelperTest < ActionView::TestCase
def test_form_for_with_labelled_builder_with_nested_fields_for_with_options_hash
klass = nil
assert_deprecated do
form_for(:post, @post, :builder => LabelledFormBuilder) do |f|
form_for(@post, :builder => LabelledFormBuilder) do |f|
f.fields_for(:comments, Comment.new, :index => 'foo') do |nested_fields|
klass = nested_fields.class
''
end
end
end
assert_equal LabelledFormBuilder, klass
end
@ -1723,52 +1651,40 @@ class FormHelperTest < ActionView::TestCase
def test_form_for_with_labelled_builder_with_nested_fields_for_with_custom_builder
klass = nil
assert_deprecated do
form_for(:post, @post, :builder => LabelledFormBuilder) do |f|
form_for(@post, :builder => LabelledFormBuilder) do |f|
f.fields_for(:comments, Comment.new, :builder => LabelledFormBuilderSubclass) do |nested_fields|
klass = nested_fields.class
''
end
end
end
assert_equal LabelledFormBuilderSubclass, klass
end
def test_form_for_with_html_options_adds_options_to_form_tag
assert_deprecated do
form_for(:post, @post, :html => {:id => 'some_form', :class => 'some_class'}) do |f| end
end
expected = whole_form("/", "some_form", "some_class")
form_for(@post, :html => {:id => 'some_form', :class => 'some_class'}) do |f| end
expected = whole_form("/posts/123", "some_form", "some_class", 'put')
assert_dom_equal expected, output_buffer
end
def test_form_for_with_string_url_option
assert_deprecated do
form_for(:post, @post, :url => 'http://www.otherdomain.com') do |f| end
end
form_for(@post, :url => 'http://www.otherdomain.com') do |f| end
assert_equal whole_form("http://www.otherdomain.com"), output_buffer
# assert_equal '<form action="http://www.otherdomain.com" method="post"></form>', output_buffer
assert_equal whole_form("http://www.otherdomain.com", 'edit_post_123', 'edit_post', 'put'), output_buffer
end
def test_form_for_with_hash_url_option
assert_deprecated do
form_for(:post, @post, :url => {:controller => 'controller', :action => 'action'}) do |f| end
end
form_for(@post, :url => {:controller => 'controller', :action => 'action'}) do |f| end
assert_equal 'controller', @url_for_options[:controller]
assert_equal 'action', @url_for_options[:action]
end
def test_form_for_with_record_url_option
assert_deprecated do
form_for(:post, @post, :url => @post) do |f| end
end
form_for(@post, :url => @post) do |f| end
expected = whole_form("/posts/123")
# expected = "<form action=\"/posts/123\" method=\"post\"></form>"
expected = whole_form("/posts/123", 'edit_post_123', 'edit_post', 'put')
assert_equal expected, output_buffer
end