Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
570c54c3
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,发现更多精彩内容 >>
提交
570c54c3
编写于
4月 05, 2010
作者:
J
Joshua Peek
提交者:
Jeremy Kemper
4月 05, 2010
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix cookie access in integration tests with other host names
上级
d270da56
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
66 addition
and
7 deletion
+66
-7
actionpack/lib/action_dispatch/testing/integration.rb
actionpack/lib/action_dispatch/testing/integration.rb
+21
-7
actionpack/test/controller/integration_test.rb
actionpack/test/controller/integration_test.rb
+45
-0
未找到文件。
actionpack/lib/action_dispatch/testing/integration.rb
浏览文件 @
570c54c3
...
...
@@ -137,7 +137,10 @@ class Session
end
# The hostname used in the last request.
attr_accessor
:host
def
host
@host
||
DEFAULT_HOST
end
attr_writer
:host
# The remote_addr used in the last request.
attr_accessor
:remote_addr
...
...
@@ -148,7 +151,7 @@ class Session
# A map of the cookies returned by the last response, and which will be
# sent with the next request.
def
cookies
@
mock_session
.
cookie_jar
_
mock_session
.
cookie_jar
end
# A reference to the controller instance used by the last request.
...
...
@@ -189,8 +192,8 @@ def default_url_options
# session.reset!
def
reset!
@https
=
false
@mock_session
=
Rack
::
MockSession
.
new
(
@app
,
DEFAULT_HOST
)
@controller
=
@request
=
@response
=
nil
@_mock_session
=
nil
@request_count
=
0
self
.
host
=
DEFAULT_HOST
...
...
@@ -234,6 +237,9 @@ def host!(name)
end
private
def
_mock_session
@_mock_session
||=
Rack
::
MockSession
.
new
(
@app
,
host
)
end
# Performs the actual request.
def
process
(
method
,
path
,
parameters
=
nil
,
rack_environment
=
nil
)
...
...
@@ -254,7 +260,7 @@ def process(method, path, parameters = nil, rack_environment = nil)
:method
=>
method
,
:params
=>
parameters
,
"SERVER_NAME"
=>
host
,
"SERVER_NAME"
=>
host
.
split
(
':'
)[
0
]
,
"SERVER_PORT"
=>
(
https?
?
"443"
:
"80"
),
"HTTPS"
=>
https?
?
"on"
:
"off"
,
"rack.url_scheme"
=>
https?
?
"https"
:
"http"
,
...
...
@@ -266,17 +272,25 @@ def process(method, path, parameters = nil, rack_environment = nil)
"HTTP_ACCEPT"
=>
accept
}
session
=
Rack
::
Test
::
Session
.
new
(
@
mock_session
)
session
=
Rack
::
Test
::
Session
.
new
(
_
mock_session
)
(
rack_environment
||
{}).
each
do
|
key
,
value
|
env
[
key
]
=
value
end
session
.
request
(
path
,
env
)
# NOTE: rack-test v0.5 doesn't build a default uri correctly
# Make sure requested path is always a full uri
uri
=
URI
.
parse
(
'/'
)
uri
.
scheme
||=
env
[
'rack.url_scheme'
]
uri
.
host
||=
env
[
'SERVER_NAME'
]
uri
.
port
||=
env
[
'SERVER_PORT'
].
try
(
:to_i
)
uri
+=
path
session
.
request
(
uri
.
to_s
,
env
)
@request_count
+=
1
@request
=
ActionDispatch
::
Request
.
new
(
session
.
last_request
.
env
)
response
=
@
mock_session
.
last_response
response
=
_
mock_session
.
last_response
@response
=
ActionDispatch
::
TestResponse
.
new
(
response
.
status
,
response
.
headers
,
response
.
body
)
@html_document
=
nil
...
...
actionpack/test/controller/integration_test.rb
浏览文件 @
570c54c3
...
...
@@ -245,6 +245,15 @@ def cookie_monster
render
:text
=>
"Gone"
,
:status
=>
410
end
def
set_cookie
cookies
[
"foo"
]
=
'bar'
head
:ok
end
def
get_cookie
render
:text
=>
cookies
[
"foo"
]
end
def
redirect
redirect_to
:action
=>
"get"
end
...
...
@@ -292,6 +301,42 @@ def test_post
end
end
test
'cookie persist to next request'
do
with_test_route_set
do
get
'/set_cookie'
assert_response
:success
assert_equal
"foo=bar; path=/"
,
headers
[
"Set-Cookie"
]
assert_equal
({
"foo"
=>
"bar"
},
cookies
.
to_hash
)
get
'/get_cookie'
assert_response
:success
assert_equal
"bar"
,
body
assert_equal
nil
,
headers
[
"Set-Cookie"
]
assert_equal
({
"foo"
=>
"bar"
},
cookies
.
to_hash
)
end
end
test
'cookie persist to next request on another domain'
do
with_test_route_set
do
host!
"37s.backpack.test"
get
'/set_cookie'
assert_response
:success
assert_equal
"foo=bar; path=/"
,
headers
[
"Set-Cookie"
]
assert_equal
({
"foo"
=>
"bar"
},
cookies
.
to_hash
)
get
'/get_cookie'
assert_response
:success
assert_equal
"bar"
,
body
assert_equal
nil
,
headers
[
"Set-Cookie"
]
assert_equal
({
"foo"
=>
"bar"
},
cookies
.
to_hash
)
end
end
def
test_redirect
with_test_route_set
do
get
'/redirect'
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录