Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
c6746ffa
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c6746ffa
编写于
4月 05, 2010
作者:
S
Santiago Pastorino
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
deprecate form_for(symbol_or_string, ...) in favor of :object_name option
上级
89978f10
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
336 addition
and
216 deletion
+336
-216
actionpack/lib/action_view/helpers/form_helper.rb
actionpack/lib/action_view/helpers/form_helper.rb
+9
-4
actionpack/test/template/form_helper_test.rb
actionpack/test/template/form_helper_test.rb
+327
-212
未找到文件。
actionpack/lib/action_view/helpers/form_helper.rb
浏览文件 @
c6746ffa
...
...
@@ -300,15 +300,16 @@ def form_for(record_or_name_or_array, *args, &proc)
case
record_or_name_or_array
when
String
,
Symbol
ActiveSupport
::
Deprecation
.
warn
(
"Use the option :object_name => ... instead of a Symbol or String as a the first argument"
,
caller
)
object_name
=
record_or_name_or_array
when
Array
object
=
record_or_name_or_array
.
last
object_name
=
ActionController
::
RecordIdentifier
.
singular_class_name
(
object
)
object_name
=
options
[
:object_name
]
||
ActionController
::
RecordIdentifier
.
singular_class_name
(
object
)
apply_form_for_options!
(
record_or_name_or_array
,
options
)
args
.
unshift
object
else
object
=
record_or_name_or_array
object_name
=
ActionController
::
RecordIdentifier
.
singular_class_name
(
object
)
object_name
=
options
[
:object_name
]
||
ActionController
::
RecordIdentifier
.
singular_class_name
(
object
)
apply_form_for_options!
([
object
],
options
)
args
.
unshift
object
end
...
...
@@ -326,9 +327,13 @@ def apply_form_for_options!(object_or_array, options) #:nodoc:
html_options
=
if
object
.
respond_to?
(
:persisted?
)
&&
object
.
persisted?
{
:class
=>
dom_class
(
object
,
:edit
),
:id
=>
dom_id
(
object
,
:edit
),
:method
=>
:put
}
{
:class
=>
options
[
:object_name
]
?
"
#{
options
[
:object_name
]
}
_edit"
:
dom_class
(
object
,
:edit
),
:id
=>
options
[
:object_name
]
?
"
#{
options
[
:object_name
]
}
_edit"
:
dom_id
(
object
,
:edit
),
:method
=>
:put
}
else
{
:class
=>
dom_class
(
object
,
:new
),
:id
=>
dom_id
(
object
),
:method
=>
:post
}
{
:class
=>
options
[
:object_name
]
?
"
#{
options
[
:object_name
]
}
_new"
:
dom_class
(
object
,
:new
),
:id
=>
options
[
:object_name
]
?
"
#{
options
[
:object_name
]
}
_new"
:
dom_id
(
object
),
:method
=>
:post
}
end
options
[
:html
]
||=
{}
...
...
actionpack/test/template/form_helper_test.rb
浏览文件 @
c6746ffa
...
...
@@ -416,6 +416,7 @@ def test_auto_index
end
def
test_form_for
assert_deprecated
do
form_for
(
:post
,
@post
,
:html
=>
{
:id
=>
'create-post'
})
do
|
f
|
concat
f
.
label
(
:title
)
concat
f
.
text_field
(
:title
)
...
...
@@ -423,6 +424,7 @@ def test_form_for
concat
f
.
check_box
(
:secret
)
concat
f
.
submit
(
'Create post'
)
end
end
expected
=
"<form action='http://www.example.com' id='create-post' method='post'>"
+
...
...
@@ -437,12 +439,36 @@ def test_form_for
assert_dom_equal
expected
,
output_buffer
end
def
test_form_for_with_symbol_object_name
form_for
(
@post
,
:object_name
=>
"other_name"
,
:html
=>
{
:id
=>
'create-post'
})
do
|
f
|
concat
f
.
label
(
:title
)
concat
f
.
text_field
(
:title
)
concat
f
.
text_area
(
:body
)
concat
f
.
check_box
(
:secret
)
concat
f
.
submit
(
'Create post'
)
end
expected
=
"<form class='other_name_edit' method='post' action='/posts/123' id='create-post'>"
+
"<div style='margin:0;padding:0;display:inline'><input name='_method' value='put' type='hidden' /></div>"
+
"<label for='other_name_title'>Title</label>"
+
"<input name='other_name[title]' size='30' id='other_name_title' value='Hello World' type='text' />"
+
"<textarea name='other_name[body]' id='other_name_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>"
+
"<input name='other_name[secret]' value='0' type='hidden' />"
+
"<input name='other_name[secret]' checked='checked' id='other_name_secret' value='1' type='checkbox' />"
+
"<input name='commit' id='other_name_submit' value='Create post' type='submit' /></form>"
assert_dom_equal
expected
,
output_buffer
end
def
test_form_for_with_method
assert_deprecated
do
form_for
(
:post
,
@post
,
: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
=
"<form action='http://www.example.com' id='create-post' method='post'>"
+
...
...
@@ -457,11 +483,13 @@ def test_form_for_with_method
end
def
test_form_for_with_remote
assert_deprecated
do
form_for
(
:post
,
@post
,
: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
=
"<form action='http://www.example.com' id='create-post' method='post' data-remote='true'>"
+
...
...
@@ -476,11 +504,13 @@ def test_form_for_with_remote
end
def
test_form_for_without_object
assert_deprecated
do
form_for
(
:post
,
:html
=>
{
:id
=>
'create-post'
})
do
|
f
|
concat
f
.
text_field
(
:title
)
concat
f
.
text_area
(
:body
)
concat
f
.
check_box
(
:secret
)
end
end
expected
=
"<form action='http://www.example.com' id='create-post' method='post'>"
+
...
...
@@ -494,16 +524,18 @@ 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
end
expected
=
"<form action='http://www.example.com' method='post'>"
+
"<label for=
\"
post_123_title
\"
>Title</label>"
+
"<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>"
+
"<input name='post[123][secret]' type='hidden' value='0' />"
+
...
...
@@ -514,11 +546,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
end
expected
=
"<form action='http://www.example.com' method='post'>"
+
...
...
@@ -535,9 +569,11 @@ def test_submit_with_object_as_new_record_and_locale_strings
old_locale
,
I18n
.
locale
=
I18n
.
locale
,
:submit
@post
.
persisted
=
false
assert_deprecated
do
form_for
(
:post
,
@post
)
do
|
f
|
concat
f
.
submit
end
end
expected
=
"<form action='http://www.example.com' method='post'>"
+
"<input name='commit' id='post_submit' type='submit' value='Create Post' />"
+
...
...
@@ -550,9 +586,11 @@ def test_submit_with_object_as_new_record_and_locale_strings
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
|
concat
f
.
submit
end
end
expected
=
"<form action='http://www.example.com' method='post'>"
+
"<input name='commit' id='post_submit' type='submit' value='Confirm Post changes' />"
+
...
...
@@ -565,9 +603,11 @@ def test_submit_with_object_as_existing_record_and_locale_strings
def
test_submit_without_object_and_locale_strings
old_locale
,
I18n
.
locale
=
I18n
.
locale
,
:submit
assert_deprecated
do
form_for
(
:post
)
do
|
f
|
concat
f
.
submit
:class
=>
"extra"
end
end
expected
=
"<form action='http://www.example.com' method='post'>"
+
"<input name='commit' class='extra' id='post_submit' type='submit' value='Save changes' />"
+
...
...
@@ -580,9 +620,11 @@ def test_submit_without_object_and_locale_strings
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
|
concat
f
.
submit
end
end
expected
=
"<form action='http://www.example.com' method='post'>"
+
"<input name='commit' id='another_post_submit' type='submit' value='Update your Post' />"
+
...
...
@@ -593,11 +635,13 @@ def test_submit_with_object_and_nested_lookup
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
)
}
end
end
expected
=
"<form action='http://www.example.com' method='post'>"
+
"<input name='post[comment][title]' size='30' type='text' id='post_comment_title' value='Hello World' />"
+
...
...
@@ -607,12 +651,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
end
expected
=
"<form action='http://www.example.com' method='post'>"
+
"<input name='post[123][title]' size='30' type='text' id='post_123_title' value='Hello World' />"
+
...
...
@@ -623,12 +669,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
end
expected
=
"<form action='http://www.example.com' method='post'>"
+
"<input name='post[1][title]' size='30' type='text' id='post_1_title' value='Hello World' />"
+
...
...
@@ -639,11 +687,13 @@ def test_nested_fields_for_with_index_and_parent_fields
end
def
test_form_for_with_index_and_nested_fields_for
assert_deprecated
do
output_buffer
=
form_for
(
:post
,
@post
,
:index
=>
1
)
do
|
f
|
concat
f
.
fields_for
(
:comment
,
@post
)
{
|
c
|
concat
c
.
text_field
(
:title
)
}
end
end
expected
=
"<form action='http://www.example.com' method='post'>"
+
"<input name='post[1][comment][title]' size='30' type='text' id='post_1_comment_title' value='Hello World' />"
+
...
...
@@ -653,11 +703,13 @@ def test_form_for_with_index_and_nested_fields_for
end
def
test_nested_fields_for_with_index_on_both
assert_deprecated
do
form_for
(
:post
,
@post
,
:index
=>
1
)
do
|
f
|
concat
f
.
fields_for
(
:comment
,
@post
,
:index
=>
5
)
{
|
c
|
concat
c
.
text_field
(
:title
)
}
end
end
expected
=
"<form action='http://www.example.com' method='post'>"
+
"<input name='post[1][comment][5][title]' size='30' type='text' id='post_1_comment_5_title' value='Hello World' />"
+
...
...
@@ -667,11 +719,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
end
expected
=
"<form action='http://www.example.com' method='post'>"
+
"<input name='post[123][comment][title]' size='30' type='text' id='post_123_comment_title' value='Hello World' />"
+
...
...
@@ -681,11 +735,13 @@ def test_nested_fields_for_with_auto_index
end
def
test_nested_fields_for_with_index_radio_button
assert_deprecated
do
form_for
(
:post
,
@post
)
do
|
f
|
concat
f
.
fields_for
(
:comment
,
@post
,
:index
=>
5
)
{
|
c
|
concat
c
.
radio_button
(
:title
,
"hello"
)
}
end
end
expected
=
"<form action='http://www.example.com' method='post'>"
+
"<input name='post[comment][5][title]' type='radio' id='post_comment_5_title_hello' value='hello' />"
+
...
...
@@ -695,11 +751,13 @@ 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
end
expected
=
"<form action='http://www.example.com' method='post'>"
+
"<input name='post[123][comment][123][title]' size='30' type='text' id='post_123_comment_123_title' value='Hello World' />"
+
...
...
@@ -709,6 +767,7 @@ def test_nested_fields_for_with_auto_index_on_both
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
)
...
...
@@ -730,16 +789,19 @@ def test_nested_fields_for_with_index_and_auto_index
assert_dom_equal
expected
,
output_buffer
end
end
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
|
concat
f
.
text_field
(
:title
)
concat
f
.
fields_for
(
:author
)
{
|
af
|
concat
af
.
text_field
(
:name
)
}
end
end
expected
=
'<form action="http://www.example.com" method="post">'
+
'<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />'
+
...
...
@@ -750,6 +812,7 @@ def test_nested_fields_for_with_a_new_record_on_a_nested_attributes_one_to_one_a
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
|
f
.
fields_for
(
:author
,
Author
.
new
(
123
))
do
|
af
|
assert_not_nil
af
.
object
...
...
@@ -757,16 +820,19 @@ def test_nested_fields_for_with_explicitly_passed_object_on_a_nested_attributes_
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
|
concat
f
.
text_field
(
:title
)
concat
f
.
fields_for
(
:author
)
{
|
af
|
concat
af
.
text_field
(
:name
)
}
end
end
expected
=
'<form action="http://www.example.com" method="post">'
+
'<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />'
+
...
...
@@ -780,6 +846,7 @@ def test_nested_fields_for_with_an_existing_record_on_a_nested_attributes_one_to
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
|
concat
f
.
text_field
(
:title
)
concat
f
.
fields_for
(
:author
)
{
|
af
|
...
...
@@ -787,6 +854,7 @@ def test_nested_fields_for_with_existing_records_on_a_nested_attributes_one_to_o
concat
af
.
text_field
(
:name
)
}
end
end
expected
=
'<form action="http://www.example.com" method="post">'
+
'<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />'
+
...
...
@@ -800,6 +868,7 @@ def test_nested_fields_for_with_existing_records_on_a_nested_attributes_one_to_o
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
|
concat
f
.
text_field
(
:title
)
@post
.
comments
.
each
do
|
comment
|
...
...
@@ -808,6 +877,7 @@ def test_nested_fields_for_with_existing_records_on_a_nested_attributes_collecti
}
end
end
end
expected
=
'<form action="http://www.example.com" method="post">'
+
'<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />'
+
...
...
@@ -823,6 +893,7 @@ def test_nested_fields_for_with_existing_records_on_a_nested_attributes_collecti
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
|
concat
f
.
text_field
(
:title
)
@post
.
comments
.
each
do
|
comment
|
...
...
@@ -832,6 +903,7 @@ def test_nested_fields_for_with_existing_records_on_a_nested_attributes_collecti
}
end
end
end
expected
=
'<form action="http://www.example.com" method="post">'
+
'<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />'
+
...
...
@@ -847,6 +919,7 @@ def test_nested_fields_for_with_existing_records_on_a_nested_attributes_collecti
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
|
concat
f
.
text_field
(
:title
)
@post
.
comments
.
each
do
|
comment
|
...
...
@@ -855,6 +928,7 @@ def test_nested_fields_for_with_new_records_on_a_nested_attributes_collection_as
}
end
end
end
expected
=
'<form action="http://www.example.com" method="post">'
+
'<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />'
+
...
...
@@ -868,6 +942,7 @@ def test_nested_fields_for_with_new_records_on_a_nested_attributes_collection_as
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
|
concat
f
.
text_field
(
:title
)
@post
.
comments
.
each
do
|
comment
|
...
...
@@ -876,6 +951,7 @@ def test_nested_fields_for_with_existing_and_new_records_on_a_nested_attributes_
}
end
end
end
expected
=
'<form action="http://www.example.com" method="post">'
+
'<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />'
+
...
...
@@ -888,12 +964,14 @@ def test_nested_fields_for_with_existing_and_new_records_on_a_nested_attributes_
end
def
test_nested_fields_for_with_an_empty_supplied_attributes_collection
assert_deprecated
do
form_for
(
:post
,
@post
)
do
|
f
|
concat
f
.
text_field
(
:title
)
f
.
fields_for
(
:comments
,
[])
do
|
cf
|
concat
cf
.
text_field
(
:name
)
end
end
end
expected
=
'<form action="http://www.example.com" method="post">'
+
'<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />'
+
...
...
@@ -905,12 +983,14 @@ def test_nested_fields_for_with_an_empty_supplied_attributes_collection
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
|
concat
f
.
text_field
(
:title
)
concat
f
.
fields_for
(
:comments
,
@post
.
comments
)
{
|
cf
|
concat
cf
.
text_field
(
:name
)
}
end
end
expected
=
'<form action="http://www.example.com" method="post">'
+
'<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />'
+
...
...
@@ -927,12 +1007,14 @@ def test_nested_fields_for_with_existing_records_on_a_supplied_nested_attributes
comments
=
Array
.
new
(
2
)
{
|
id
|
Comment
.
new
(
id
+
1
)
}
@post
.
comments
=
[]
assert_deprecated
do
form_for
(
:post
,
@post
)
do
|
f
|
concat
f
.
text_field
(
:title
)
concat
f
.
fields_for
(
:comments
,
comments
)
{
|
cf
|
concat
cf
.
text_field
(
:name
)
}
end
end
expected
=
'<form action="http://www.example.com" method="post">'
+
'<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />'
+
...
...
@@ -949,6 +1031,7 @@ def test_nested_fields_for_on_a_nested_attributes_collection_association_yields_
@post
.
comments
=
[
Comment
.
new
(
321
),
Comment
.
new
]
yielded_comments
=
[]
assert_deprecated
do
form_for
(
:post
,
@post
)
do
|
f
|
concat
f
.
text_field
(
:title
)
concat
f
.
fields_for
(
:comments
)
{
|
cf
|
...
...
@@ -956,6 +1039,7 @@ def test_nested_fields_for_on_a_nested_attributes_collection_association_yields_
yielded_comments
<<
cf
.
object
}
end
end
expected
=
'<form action="http://www.example.com" method="post">'
+
'<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />'
+
...
...
@@ -971,11 +1055,13 @@ def test_nested_fields_for_on_a_nested_attributes_collection_association_yields_
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
|
concat
f
.
fields_for
(
:comments
,
Comment
.
new
(
321
),
:child_index
=>
'abc'
)
{
|
cf
|
concat
cf
.
text_field
(
:name
)
}
end
end
expected
=
'<form action="http://www.example.com" method="post">'
+
'<input id="post_comments_attributes_abc_name" name="post[comments_attributes][abc][name]" size="30" type="text" value="comment #321" />'
+
...
...
@@ -991,6 +1077,8 @@ def test_nested_fields_uses_unique_indices_for_different_collection_associations
@post
.
comments
[
0
].
relevances
=
[]
@post
.
tags
[
0
].
relevances
=
[]
@post
.
tags
[
1
].
relevances
=
[]
assert_deprecated
do
form_for
(
:post
,
@post
)
do
|
f
|
concat
f
.
fields_for
(
:comments
,
@post
.
comments
[
0
])
{
|
cf
|
concat
cf
.
text_field
(
:name
)
...
...
@@ -1011,6 +1099,7 @@ def test_nested_fields_uses_unique_indices_for_different_collection_associations
}
}
end
end
expected
=
'<form action="http://www.example.com" method="post">'
+
'<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" size="30" type="text" value="comment #321" />'
+
...
...
@@ -1153,6 +1242,7 @@ def test_form_builder_does_not_have_form_for_method
end
def
test_form_for_and_fields_for
assert_deprecated
do
form_for
(
:post
,
@post
,
:html
=>
{
:id
=>
'create-post'
})
do
|
post_form
|
concat
post_form
.
text_field
(
:title
)
concat
post_form
.
text_area
(
:body
)
...
...
@@ -1161,6 +1251,7 @@ def test_form_for_and_fields_for
concat
parent_fields
.
check_box
(
:secret
)
}
end
end
expected
=
"<form action='http://www.example.com' id='create-post' method='post'>"
+
...
...
@@ -1174,6 +1265,7 @@ def test_form_for_and_fields_for
end
def
test_form_for_and_fields_for_with_object
assert_deprecated
do
form_for
(
:post
,
@post
,
:html
=>
{
:id
=>
'create-post'
})
do
|
post_form
|
concat
post_form
.
text_field
(
:title
)
concat
post_form
.
text_area
(
:body
)
...
...
@@ -1182,6 +1274,7 @@ def test_form_for_and_fields_for_with_object
concat
comment_fields
.
text_field
(
:name
)
}
end
end
expected
=
"<form action='http://www.example.com' id='create-post' method='post'>"
+
...
...
@@ -1205,11 +1298,13 @@ def #{selector}(field, *args, &proc)
end
def
test_form_for_with_labelled_builder
assert_deprecated
do
form_for
(
:post
,
@post
,
:builder
=>
LabelledFormBuilder
)
do
|
f
|
concat
f
.
text_field
(
:title
)
concat
f
.
text_area
(
:body
)
concat
f
.
check_box
(
:secret
)
end
end
expected
=
"<form action='http://www.example.com' method='post'>"
+
...
...
@@ -1225,11 +1320,13 @@ 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
|
concat
f
.
text_field
(
:title
)
concat
f
.
text_area
(
:body
)
concat
f
.
check_box
(
:secret
)
end
end
expected
=
"<form action='http://www.example.com' method='post'>"
+
...
...
@@ -1244,10 +1341,12 @@ def test_default_form_builder
end
def
test_default_form_builder_with_active_record_helpers
assert_deprecated
do
form_for
(
:post
,
@post
)
do
|
f
|
concat
f
.
error_message_on
(
'author_name'
)
concat
f
.
error_messages
end
end
expected
=
%(<form action='http://www.example.com' method='post'>)
+
%(<div class='formError'>can't be empty</div>)
+
...
...
@@ -1262,10 +1361,12 @@ def test_default_form_builder_no_instance_variable
post
=
@post
@post
=
nil
assert_deprecated
do
form_for
(
:post
,
post
)
do
|
f
|
concat
f
.
error_message_on
(
'author_name'
)
concat
f
.
error_messages
end
end
expected
=
%(<form action='http://www.example.com' method='post'>)
+
%(<div class='formError'>can't be empty</div>)
+
...
...
@@ -1294,12 +1395,14 @@ def test_fields_for_with_labelled_builder
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
|
f
.
fields_for
(
:comments
,
Comment
.
new
)
do
|
nested_fields
|
klass
=
nested_fields
.
class
''
end
end
end
assert_equal
LabelledFormBuilder
,
klass
end
...
...
@@ -1307,12 +1410,14 @@ def test_form_for_with_labelled_builder_with_nested_fields_for_without_options_h
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
|
f
.
fields_for
(
:comments
,
Comment
.
new
,
:index
=>
'foo'
)
do
|
nested_fields
|
klass
=
nested_fields
.
class
''
end
end
end
assert_equal
LabelledFormBuilder
,
klass
end
...
...
@@ -1322,38 +1427,48 @@ class LabelledFormBuilderSubclass < LabelledFormBuilder; end
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
|
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
=
"<form action=
\"
http://www.example.com
\"
class=
\"
some_class
\"
id=
\"
some_form
\"
method=
\"
post
\"
></form>"
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
assert_equal
'<form action="http://www.otherdomain.com" method="post"></form>'
,
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
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
expected
=
"<form action=
\"
/posts/123
\"
method=
\"
post
\"
></form>"
assert_equal
expected
,
output_buffer
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录