Permalink
Browse files

Remove last tests with deprecated form_for and cleanup form_for helper

This cleans up the last bits of deprecation stuff from form_for helper.
However there is still a bug when using :as => foo[], with index. The
classes and ids are being generated using [], such as foo[]_edit. This
bug already existed but it was not detected before.
  • Loading branch information...
1 parent db57e92 commit 63458994896c6e1b57f5c8716c637d74f1bb1c9e @carlosantoniodasilva carlosantoniodasilva committed with josevalim Sep 25, 2010
Showing with 51 additions and 67 deletions.
  1. +2 −4 actionpack/lib/action_view/helpers/form_helper.rb
  2. +49 −63 actionpack/test/template/form_helper_test.rb
@@ -293,18 +293,16 @@ module FormHelper
#
# If you don't need to attach a form to a model instance, then check out
# FormTagHelper#form_tag.
- def form_for(record, record_object = nil, options = nil, &proc)
+ def form_for(record, options = nil, &proc)
raise ArgumentError, "Missing block" unless block_given?
- options, record_object = record_object, nil if record_object.is_a?(Hash)
options ||= {}
options[:html] ||= {}
case record
when String, Symbol
- ActiveSupport::Deprecation.warn("Using form_for(:name, @resource) is deprecated. Please use form_for(@resource, :as => :name) instead.", caller) if record_object
object_name = record
- object = record_object
+ object = nil
else
object = record.is_a?(Array) ? record.last : record
object_name = options[:as] || ActiveModel::Naming.param_key(object)
@@ -816,16 +816,14 @@ def test_form_for_without_object
end
def test_form_for_with_index
- assert_deprecated do
- form_for("post[]", @post) do |f|
- concat f.label(:title)
- concat f.text_field(:title)
- concat f.text_area(:body)
- concat f.check_box(:secret)
- end
+ form_for(@post, :as => "post[]") do |f|
+ concat f.label(:title)
+ concat f.text_field(:title)
+ concat f.text_area(:body)
+ concat f.check_box(:secret)
end
- expected = whole_form do
+ expected = whole_form('/posts/123', 'post[]_edit', 'post[]_edit', 'put') do
"<label for='post_123_title'>Title</label>" +
"<input name='post[123][title]' size='30' type='text' id='post_123_title' value='Hello World' />" +
"<textarea name='post[123][body]' id='post_123_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
@@ -837,15 +835,13 @@ def test_form_for_with_index
end
def test_form_for_with_nil_index_option_override
- assert_deprecated do
- form_for("post[]", @post, :index => nil) do |f|
- concat f.text_field(:title)
- concat f.text_area(:body)
- concat f.check_box(:secret)
- end
+ form_for(@post, :as => "post[]", :index => nil) do |f|
+ concat f.text_field(:title)
+ concat f.text_area(:body)
+ concat f.check_box(:secret)
end
- expected = whole_form do
+ expected = whole_form('/posts/123', 'post[]_edit', 'post[]_edit', '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' />" +
@@ -936,16 +932,14 @@ def test_nested_fields_for
end
def test_nested_fields_for_with_nested_collections
- assert_deprecated do
- form_for('post[]', @post) do |f|
- concat f.text_field(:title)
- concat f.fields_for('comment[]', @comment) { |c|
- concat c.text_field(:name)
- }
- end
+ form_for(@post, :as => 'post[]') do |f|
+ concat f.text_field(:title)
+ concat f.fields_for('comment[]', @comment) { |c|
+ concat c.text_field(:name)
+ }
end
- expected = whole_form do
+ expected = whole_form('/posts/123', 'post[]_edit', 'post[]_edit', 'put') do
"<input name='post[123][title]' size='30' type='text' id='post_123_title' value='Hello World' />" +
"<input name='post[123][comment][][name]' size='30' type='text' id='post_123_comment__name' value='new comment' />"
end
@@ -954,16 +948,14 @@ def test_nested_fields_for_with_nested_collections
end
def test_nested_fields_for_with_index_and_parent_fields
- assert_deprecated do
- form_for('post', @post, :index => 1) do |c|
- concat c.text_field(:title)
- concat c.fields_for('comment', @comment, :index => 1) { |r|
- concat r.text_field(:name)
- }
- end
+ form_for(@post, :index => 1) do |c|
+ concat c.text_field(:title)
+ concat c.fields_for('comment', @comment, :index => 1) { |r|
+ concat r.text_field(:name)
+ }
end
- expected = whole_form do
+ expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', 'put') do
"<input name='post[1][title]' size='30' type='text' id='post_1_title' value='Hello World' />" +
"<input name='post[1][comment][1][name]' size='30' type='text' id='post_1_comment_1_name' value='new comment' />"
end
@@ -1000,15 +992,13 @@ def test_nested_fields_for_with_index_on_both
end
def test_nested_fields_for_with_auto_index
- assert_deprecated do
- form_for("post[]", @post) do |f|
- concat f.fields_for(:comment, @post) { |c|
- concat c.text_field(:title)
- }
- end
+ form_for(@post, :as => "post[]") do |f|
+ concat f.fields_for(:comment, @post) { |c|
+ concat c.text_field(:title)
+ }
end
- expected = whole_form do
+ expected = whole_form('/posts/123', 'post[]_edit', 'post[]_edit', 'put') do
"<input name='post[123][comment][title]' size='30' type='text' id='post_123_comment_title' value='Hello World' />"
end
@@ -1030,43 +1020,39 @@ def test_nested_fields_for_with_index_radio_button
end
def test_nested_fields_for_with_auto_index_on_both
- assert_deprecated do
- form_for("post[]", @post) do |f|
- concat f.fields_for("comment[]", @post) { |c|
- concat c.text_field(:title)
- }
- end
+ form_for(@post, :as => "post[]") do |f|
+ concat f.fields_for("comment[]", @post) { |c|
+ concat c.text_field(:title)
+ }
end
- expected = whole_form do
+ expected = whole_form('/posts/123', 'post[]_edit', 'post[]_edit', 'put') do
"<input name='post[123][comment][123][title]' size='30' type='text' id='post_123_comment_123_title' value='Hello World' />"
end
assert_dom_equal expected, output_buffer
end
def test_nested_fields_for_with_index_and_auto_index
- assert_deprecated do
- output_buffer = form_for("post[]", @post) do |f|
- concat f.fields_for(:comment, @post, :index => 5) { |c|
- concat c.text_field(:title)
- }
- end
-
- output_buffer << form_for(:post, @post, :index => 1) do |f|
- concat f.fields_for("comment[]", @post) { |c|
- concat c.text_field(:title)
- }
- end
+ output_buffer = form_for(@post, :as => "post[]") do |f|
+ concat f.fields_for(:comment, @post, :index => 5) { |c|
+ concat c.text_field(:title)
+ }
+ end
- expected = whole_form do
- "<input name='post[123][comment][5][title]' size='30' type='text' id='post_123_comment_5_title' value='Hello World' />"
- end + whole_form do
- "<input name='post[1][comment][123][title]' size='30' type='text' id='post_1_comment_123_title' value='Hello World' />"
- end
+ output_buffer << form_for(@post, :as => :post, :index => 1) do |f|
+ concat f.fields_for("comment[]", @post) { |c|
+ concat c.text_field(:title)
+ }
+ end
- assert_dom_equal expected, output_buffer
+ expected = whole_form('/posts/123', 'post[]_edit', 'post[]_edit', 'put') do
+ "<input name='post[123][comment][5][title]' size='30' type='text' id='post_123_comment_5_title' value='Hello World' />"
+ end + whole_form('/posts/123', 'post_edit', 'post_edit', 'put') do
+ "<input name='post[1][comment][123][title]' size='30' type='text' id='post_1_comment_123_title' value='Hello World' />"
end
+
+ assert_dom_equal expected, output_buffer
end
def test_nested_fields_for_with_a_new_record_on_a_nested_attributes_one_to_one_association

0 comments on commit 6345899

Please sign in to comment.