Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
10df6931
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
10df6931
编写于
9月 08, 2020
作者:
J
John Hawthorn
提交者:
GitHub
9月 08, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #40125 from jhawthorn/actionview_test_case_isolation
Use a unique controller class per ActionView::TestCase
上级
015c3932
3ec8ddd0
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
24 addition
and
24 deletion
+24
-24
actionpack/lib/action_controller/metal.rb
actionpack/lib/action_controller/metal.rb
+1
-1
actionview/lib/action_view/test_case.rb
actionview/lib/action_view/test_case.rb
+16
-23
actionview/test/template/test_case_test.rb
actionview/test/template/test_case_test.rb
+7
-0
未找到文件。
actionpack/lib/action_controller/metal.rb
浏览文件 @
10df6931
...
...
@@ -126,7 +126,7 @@ class Metal < AbstractController::Base
# ==== Returns
# * <tt>string</tt>
def
self
.
controller_name
@controller_name
||=
name
.
demodulize
.
delete_suffix
(
"Controller"
).
underscore
@controller_name
||=
(
name
.
demodulize
.
delete_suffix
(
"Controller"
).
underscore
unless
anonymous?
)
end
def
self
.
make_response!
(
request
)
...
...
actionview/lib/action_view/test_case.rb
浏览文件 @
10df6931
...
...
@@ -16,11 +16,12 @@ class TestController < ActionController::Base
attr_accessor
:request
,
:response
,
:params
class
<<
self
attr_writer
:controller_path
# Overrides AbstractController::Base#controller_path
attr_accessor
:controller_path
end
def
controller_path
=
(
path
)
self
.
class
.
controller_path
=
(
path
)
self
.
class
.
controller_path
=
path
end
def
initialize
...
...
@@ -101,7 +102,8 @@ def include_helper_modules!
end
def
setup_with_controller
@controller
=
ActionView
::
TestCase
::
TestController
.
new
controller_class
=
Class
.
new
(
ActionView
::
TestCase
::
TestController
)
@controller
=
controller_class
.
new
@request
=
@controller
.
request
@view_flow
=
ActionView
::
OutputFlow
.
new
# empty string ensures buffer has UTF-8 encoding as
...
...
@@ -109,8 +111,8 @@ def setup_with_controller
@output_buffer
=
ActiveSupport
::
SafeBuffer
.
new
""
@rendered
=
+
""
make_test_case_available_to_view!
say_no_to_protect_against_forgery!
test_case_instance
=
self
controller_class
.
define_method
(
:_test_case
)
{
test_case_instance
}
end
def
config
...
...
@@ -160,33 +162,24 @@ def view_rendered?(view, expected_locals)
included
do
setup
:setup_with_controller
ActiveSupport
.
run_load_hooks
(
:action_view_test_case
,
self
)
end
private
# Need to experiment if this priority is the best one: rendered => output_buffer
def
document_root_element
Nokogiri
::
HTML
::
Document
.
parse
(
@rendered
.
blank?
?
@output_buffer
:
@rendered
).
root
end
def
say_no_to_protect_against_forgery!
_helpers
.
module_eval
do
silence_redefinition_of_method
:protect_against_forgery?
helper
do
def
protect_against_forgery?
false
end
end
end
def
make_test_case_available_to_view!
test_case_instance
=
self
_helpers
.
module_eval
do
unless
private_method_defined?
(
:_test_case
)
define_method
(
:_test_case
)
{
test_case_instance
}
private
:_test_case
def
_test_case
controller
.
_test_case
end
end
end
private
# Need to experiment if this priority is the best one: rendered => output_buffer
def
document_root_element
Nokogiri
::
HTML
::
Document
.
parse
(
@rendered
.
blank?
?
@output_buffer
:
@rendered
).
root
end
module
Locals
attr_accessor
:rendered_views
...
...
actionview/test/template/test_case_test.rb
浏览文件 @
10df6931
...
...
@@ -156,6 +156,13 @@ def render_from_helper
assert_equal
"controller_helper_method"
,
some_method
end
class
AnotherTestClass
<
ActionView
::
TestCase
test
"doesn't use controller helpers from other tests"
do
assert_not_respond_to
view
,
:render_from_helper
assert_not_includes
@controller
.
_helpers
.
instance_methods
,
:render_from_helper
end
end
end
class
ViewAssignsTest
<
ActionView
::
TestCase
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录