Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
65113fd2
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,发现更多精彩内容 >>
提交
65113fd2
编写于
2月 04, 2013
作者:
C
Carlos Antonio da Silva
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #8520 from senny/8516_assert_template_with_locals
Improved `assert_template` when matching :locals with partials
上级
e16110c4
cce94e72
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
46 addition
and
3 deletion
+46
-3
actionpack/CHANGELOG.md
actionpack/CHANGELOG.md
+13
-1
actionpack/lib/action_controller/test_case.rb
actionpack/lib/action_controller/test_case.rb
+5
-1
actionpack/lib/action_view/test_case.rb
actionpack/lib/action_view/test_case.rb
+5
-1
actionpack/test/fixtures/test/_directory/_partial_with_locales.html.erb
...t/fixtures/test/_directory/_partial_with_locales.html.erb
+1
-0
actionpack/test/fixtures/test/render_partial_inside_directory.html.erb
...st/fixtures/test/render_partial_inside_directory.html.erb
+1
-0
actionpack/test/template/test_case_test.rb
actionpack/test/template/test_case_test.rb
+21
-0
未找到文件。
actionpack/CHANGELOG.md
浏览文件 @
65113fd2
## Rails 4.0.0 (unreleased) ##
## Rails 4.0.0 (unreleased) ##
*
`assert_template`
can be used to verify the locals of partials,
which live inside a directory.
Fixes #8516.
# Prefixed partials inside directories worked and still work.
assert_template partial: 'directory/_partial', locals: {name: 'John'}
# This did not work but does now.
assert_template partial: 'directory/partial', locals: {name: 'John'}
*Yves Senn*
*
Fix
`content_tag_for`
with array html option.
*
Fix
`content_tag_for`
with array html option.
It would embed array as string instead of joining it like
`content_tag`
does:
It would embed array as string instead of joining it like
`content_tag`
does:
...
@@ -248,7 +260,7 @@
...
@@ -248,7 +260,7 @@
*
More descriptive error messages when calling
`render :partial`
with
*
More descriptive error messages when calling
`render :partial`
with
an invalid
`:layout`
argument.
an invalid
`:layout`
argument.
Fixes #8376.
Fixes #8376.
render partial: 'partial', layout: true
render partial: 'partial', layout: true
...
...
actionpack/lib/action_controller/test_case.rb
浏览文件 @
65113fd2
...
@@ -126,7 +126,11 @@ def assert_template(options = {}, message = nil)
...
@@ -126,7 +126,11 @@ def assert_template(options = {}, message = nil)
if
expected_partial
=
options
[
:partial
]
if
expected_partial
=
options
[
:partial
]
if
expected_locals
=
options
[
:locals
]
if
expected_locals
=
options
[
:locals
]
if
defined?
(
@_rendered_views
)
if
defined?
(
@_rendered_views
)
view
=
expected_partial
.
to_s
.
sub
(
/^_/
,
''
)
view
=
expected_partial
.
to_s
.
sub
(
/^_/
,
''
).
sub
(
/\/_(?=[^\/]+\z)/
,
'/'
)
partial_was_not_rendered_msg
=
"expected %s to be rendered but it was not."
%
view
assert_includes
@_rendered_views
.
rendered_views
,
view
,
partial_was_not_rendered_msg
msg
=
'expecting %s to be rendered with %s but was with %s'
%
[
expected_partial
,
msg
=
'expecting %s to be rendered with %s but was with %s'
%
[
expected_partial
,
expected_locals
,
expected_locals
,
@_rendered_views
.
locals_for
(
view
)]
@_rendered_views
.
locals_for
(
view
)]
...
...
actionpack/lib/action_view/test_case.rb
浏览文件 @
65113fd2
...
@@ -122,7 +122,7 @@ def rendered_views
...
@@ -122,7 +122,7 @@ def rendered_views
class
RenderedViewsCollection
class
RenderedViewsCollection
def
initialize
def
initialize
@rendered_views
||=
{
}
@rendered_views
||=
Hash
.
new
{
|
hash
,
key
|
hash
[
key
]
=
[]
}
end
end
def
add
(
view
,
locals
)
def
add
(
view
,
locals
)
...
@@ -134,6 +134,10 @@ def locals_for(view)
...
@@ -134,6 +134,10 @@ def locals_for(view)
@rendered_views
[
view
]
@rendered_views
[
view
]
end
end
def
rendered_views
@rendered_views
.
keys
end
def
view_rendered?
(
view
,
expected_locals
)
def
view_rendered?
(
view
,
expected_locals
)
locals_for
(
view
).
any?
do
|
actual_locals
|
locals_for
(
view
).
any?
do
|
actual_locals
|
expected_locals
.
all?
{
|
key
,
value
|
value
==
actual_locals
[
key
]
}
expected_locals
.
all?
{
|
key
,
value
|
value
==
actual_locals
[
key
]
}
...
...
actionpack/test/fixtures/test/_directory/_partial_with_locales.html.erb
0 → 100644
浏览文件 @
65113fd2
Hello
<%=
name
%>
actionpack/test/fixtures/test/render_partial_inside_directory.html.erb
0 → 100644
浏览文件 @
65113fd2
<%=
render
partial:
'test/_directory/partial_with_locales'
,
locals:
{
'name'
=>
'Jane'
}
%>
actionpack/test/template/test_case_test.rb
浏览文件 @
65113fd2
...
@@ -329,6 +329,27 @@ class RenderTemplateTest < ActionView::TestCase
...
@@ -329,6 +329,27 @@ class RenderTemplateTest < ActionView::TestCase
assert_template
partial:
'_partial'
,
locals:
{
'second'
=>
'2'
}
assert_template
partial:
'_partial'
,
locals:
{
'second'
=>
'2'
}
end
end
test
'raises descriptive error message when template was not rendered'
do
controller
.
controller_path
=
"test"
render
(
template:
"test/hello_world_with_partial"
)
e
=
assert_raise
ActiveSupport
::
TestCase
::
Assertion
do
assert_template
partial:
'i_was_never_rendered'
,
locals:
{
'did_not'
=>
'happen'
}
end
assert_match
"i_was_never_rendered to be rendered but it was not."
,
e
.
message
assert_match
'Expected ["/test/partial"] to include "i_was_never_rendered"'
,
e
.
message
end
test
'specifying locals works when the partial is inside a directory with underline prefix'
do
controller
.
controller_path
=
"test"
render
(
template:
'test/render_partial_inside_directory'
)
assert_template
partial:
'test/_directory/_partial_with_locales'
,
locals:
{
'name'
=>
'Jane'
}
end
test
'specifying locals works when the partial is inside a directory without underline prefix'
do
controller
.
controller_path
=
"test"
render
(
template:
'test/render_partial_inside_directory'
)
assert_template
partial:
'test/_directory/partial_with_locales'
,
locals:
{
'name'
=>
'Jane'
}
end
end
end
module
AHelperWithInitialize
module
AHelperWithInitialize
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录