Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
c6a39c01
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,发现更多精彩内容 >>
提交
c6a39c01
编写于
1月 21, 2013
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #9014 from virusman/form_helpers_ar_tests
AR integration tests for form helpers
上级
ee345821
9047ca01
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
92 addition
and
0 deletion
+92
-0
actionpack/test/activerecord/form_helper_activerecord_test.rb
...onpack/test/activerecord/form_helper_activerecord_test.rb
+91
-0
actionpack/test/fixtures/developer.rb
actionpack/test/fixtures/developer.rb
+1
-0
未找到文件。
actionpack/test/activerecord/form_helper_activerecord_test.rb
0 → 100644
浏览文件 @
c6a39c01
require
'active_record_unit'
require
'fixtures/project'
require
'fixtures/developer'
class
FormHelperActiveRecordTest
<
ActionView
::
TestCase
tests
ActionView
::
Helpers
::
FormHelper
def
form_for
(
*
)
@output_buffer
=
super
end
def
setup
@developer
=
Developer
.
new
@developer
.
id
=
123
@developer
.
name
=
"developer #123"
@project
=
Project
.
new
@project
.
id
=
321
@project
.
name
=
"project #321"
@project
.
save
@developer
.
projects
<<
@project
@developer
.
save
end
def
teardown
Project
.
delete
(
321
)
Developer
.
delete
(
123
)
end
Routes
=
ActionDispatch
::
Routing
::
RouteSet
.
new
Routes
.
draw
do
resources
:developers
do
resources
:projects
end
end
def
_routes
Routes
end
include
Routes
.
url_helpers
def
test_nested_fields_for_with_child_index_option_override_on_a_nested_attributes_collection_association
form_for
(
@developer
)
do
|
f
|
concat
f
.
fields_for
(
:projects
,
@developer
.
projects
.
first
,
:child_index
=>
'abc'
)
{
|
cf
|
concat
cf
.
text_field
(
:name
)
}
end
expected
=
whole_form
(
'/developers/123'
,
'edit_developer_123'
,
'edit_developer'
,
:method
=>
'patch'
)
do
'<input id="developer_projects_attributes_abc_name" name="developer[projects_attributes][abc][name]" type="text" value="project #321" />'
+
'<input id="developer_projects_attributes_abc_id" name="developer[projects_attributes][abc][id]" type="hidden" value="321" />'
end
assert_dom_equal
expected
,
output_buffer
end
protected
def
hidden_fields
(
method
=
nil
)
txt
=
%{<div style="margin:0;padding:0;display:inline">}
txt
<<
%{<input name="utf8" type="hidden" value="✓" />}
if
method
&&
!
%w(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
,
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
method
=
method
.
to_s
==
"get"
?
"get"
:
"post"
txt
<<
%{ method="#{method}">}
end
def
whole_form
(
action
=
"/"
,
id
=
nil
,
html_class
=
nil
,
options
=
nil
)
contents
=
block_given?
?
yield
:
""
if
options
.
is_a?
(
Hash
)
method
,
remote
,
multipart
=
options
.
values_at
(
:method
,
:remote
,
:multipart
)
else
method
=
options
end
form_text
(
action
,
id
,
html_class
,
remote
,
multipart
,
method
)
+
hidden_fields
(
method
)
+
contents
+
"</form>"
end
end
\ No newline at end of file
actionpack/test/fixtures/developer.rb
浏览文件 @
c6a39c01
...
...
@@ -2,6 +2,7 @@ class Developer < ActiveRecord::Base
has_and_belongs_to_many
:projects
has_many
:replies
has_many
:topics
,
:through
=>
:replies
accepts_nested_attributes_for
:projects
end
class
DeVeLoPeR
<
ActiveRecord
::
Base
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录