Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
78a5124b
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 搜索 >>
提交
78a5124b
编写于
7月 08, 2015
作者:
A
Aaron Patterson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add a new constructor for allocating test requests
上级
db41f33d
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
31 addition
and
29 deletion
+31
-29
actionpack/lib/action_controller/test_case.rb
actionpack/lib/action_controller/test_case.rb
+13
-11
actionpack/lib/action_dispatch/testing/assertions/routing.rb
actionpack/lib/action_dispatch/testing/assertions/routing.rb
+1
-1
actionpack/lib/action_dispatch/testing/test_request.rb
actionpack/lib/action_dispatch/testing/test_request.rb
+8
-8
actionpack/test/dispatch/test_request_test.rb
actionpack/test/dispatch/test_request_test.rb
+9
-9
未找到文件。
actionpack/lib/action_controller/test_case.rb
浏览文件 @
78a5124b
...
...
@@ -14,6 +14,18 @@ def self.new_session
TestSession
.
new
end
# Create a new test request with default `env` values
def
self
.
create
env
=
{}
env
=
Rails
.
application
.
env_config
.
merge
(
env
)
if
defined?
(
Rails
.
application
)
&&
Rails
.
application
new
(
default_env
.
merge
(
env
),
new_session
)
end
def
self
.
default_env
DEFAULT_ENV
end
private_class_method
:default_env
def
initialize
(
env
,
session
)
super
(
env
)
...
...
@@ -70,12 +82,6 @@ def recycle!
@fullpath
=
@ip
=
@remote_ip
=
@protocol
=
nil
@env
[
'action_dispatch.request.query_parameters'
]
=
{}
end
private
def
default_env
DEFAULT_ENV
end
end
class
TestResponse
<
ActionDispatch
::
TestResponse
...
...
@@ -516,7 +522,7 @@ def setup_controller_request_and_response
end
end
@request
=
build_request
({},
TestRequest
.
new_session
)
@request
=
TestRequest
.
create
@request
.
env
[
"rack.request.cookie_hash"
]
=
{}.
with_indifferent_access
@response
=
build_response
@response_klass
@response
.
request
=
@request
...
...
@@ -527,10 +533,6 @@ def setup_controller_request_and_response
end
end
def
build_request
(
env
,
session
)
TestRequest
.
new
(
env
,
session
)
end
def
build_response
(
klass
)
klass
.
new
end
...
...
actionpack/lib/action_dispatch/testing/assertions/routing.rb
浏览文件 @
78a5124b
...
...
@@ -183,7 +183,7 @@ def recognized_request_for(path, extras = {}, msg)
end
# Assume given controller
request
=
build_request
({},
ActionController
::
TestRequest
.
new_session
)
request
=
ActionController
::
TestRequest
.
create
if
path
=~
%r{://}
fail_on
(
URI
::
InvalidURIError
,
msg
)
do
...
...
actionpack/lib/action_dispatch/testing/test_request.rb
浏览文件 @
78a5124b
...
...
@@ -10,11 +10,17 @@ class TestRequest < Request
"rack.request.cookie_hash"
=>
{}.
with_indifferent_access
)
def
initialize
(
env
)
# Create a new test request with default `env` values
def
self
.
create
(
env
=
{})
env
=
Rails
.
application
.
env_config
.
merge
(
env
)
if
defined?
(
Rails
.
application
)
&&
Rails
.
application
super
(
default_env
.
merge
(
env
))
new
(
default_env
.
merge
(
env
))
end
def
self
.
default_env
DEFAULT_ENV
end
private_class_method
:default_env
def
request_method
=
(
method
)
@env
[
'REQUEST_METHOD'
]
=
method
.
to_s
.
upcase
end
...
...
@@ -59,11 +65,5 @@ def accept=(mime_types)
@env
.
delete
(
'action_dispatch.request.accepts'
)
@env
[
'HTTP_ACCEPT'
]
=
Array
(
mime_types
).
collect
(
&
:to_s
).
join
(
","
)
end
private
def
default_env
DEFAULT_ENV
end
end
end
actionpack/test/dispatch/test_request_test.rb
浏览文件 @
78a5124b
...
...
@@ -2,7 +2,7 @@
class
TestRequestTest
<
ActiveSupport
::
TestCase
test
"sane defaults"
do
env
=
ActionDispatch
::
TestRequest
.
new
({})
.
env
env
=
ActionDispatch
::
TestRequest
.
create
.
env
assert_equal
"GET"
,
env
.
delete
(
"REQUEST_METHOD"
)
assert_equal
"off"
,
env
.
delete
(
"HTTPS"
)
...
...
@@ -27,7 +27,7 @@ class TestRequestTest < ActiveSupport::TestCase
end
test
"cookie jar"
do
req
=
ActionDispatch
::
TestRequest
.
new
({})
req
=
ActionDispatch
::
TestRequest
.
create
({})
assert_equal
({},
req
.
cookies
)
assert_equal
nil
,
req
.
env
[
"HTTP_COOKIE"
]
...
...
@@ -55,38 +55,38 @@ class TestRequestTest < ActiveSupport::TestCase
test
"does not complain when Rails.application is nil"
do
Rails
.
stubs
(
:application
).
returns
(
nil
)
req
=
ActionDispatch
::
TestRequest
.
new
({})
req
=
ActionDispatch
::
TestRequest
.
create
({})
assert_equal
false
,
req
.
env
.
empty?
end
test
"default remote address is 0.0.0.0"
do
req
=
ActionDispatch
::
TestRequest
.
new
({})
req
=
ActionDispatch
::
TestRequest
.
create
({})
assert_equal
'0.0.0.0'
,
req
.
remote_addr
end
test
"allows remote address to be overridden"
do
req
=
ActionDispatch
::
TestRequest
.
new
(
'REMOTE_ADDR'
=>
'127.0.0.1'
)
req
=
ActionDispatch
::
TestRequest
.
create
(
'REMOTE_ADDR'
=>
'127.0.0.1'
)
assert_equal
'127.0.0.1'
,
req
.
remote_addr
end
test
"default host is test.host"
do
req
=
ActionDispatch
::
TestRequest
.
new
({})
req
=
ActionDispatch
::
TestRequest
.
create
({})
assert_equal
'test.host'
,
req
.
host
end
test
"allows host to be overridden"
do
req
=
ActionDispatch
::
TestRequest
.
new
(
'HTTP_HOST'
=>
'www.example.com'
)
req
=
ActionDispatch
::
TestRequest
.
create
(
'HTTP_HOST'
=>
'www.example.com'
)
assert_equal
'www.example.com'
,
req
.
host
end
test
"default user agent is 'Rails Testing'"
do
req
=
ActionDispatch
::
TestRequest
.
new
({})
req
=
ActionDispatch
::
TestRequest
.
create
({})
assert_equal
'Rails Testing'
,
req
.
user_agent
end
test
"allows user agent to be overridden"
do
req
=
ActionDispatch
::
TestRequest
.
new
(
'HTTP_USER_AGENT'
=>
'GoogleBot'
)
req
=
ActionDispatch
::
TestRequest
.
create
(
'HTTP_USER_AGENT'
=>
'GoogleBot'
)
assert_equal
'GoogleBot'
,
req
.
user_agent
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录