Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
b480da5c
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,发现更多精彩内容 >>
提交
b480da5c
编写于
10月 05, 2009
作者:
J
Joshua Peek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Coerce all out going body parts to Strings
上级
570f055c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
72 addition
and
0 deletion
+72
-0
actionpack/lib/action_dispatch.rb
actionpack/lib/action_dispatch.rb
+1
-0
actionpack/lib/action_dispatch/middleware/string_coercion.rb
actionpack/lib/action_dispatch/middleware/string_coercion.rb
+29
-0
actionpack/test/abstract_unit.rb
actionpack/test/abstract_unit.rb
+1
-0
actionpack/test/dispatch/string_coercion_test.rb
actionpack/test/dispatch/string_coercion_test.rb
+40
-0
railties/lib/rails/initializer.rb
railties/lib/rails/initializer.rb
+1
-0
未找到文件。
actionpack/lib/action_dispatch.rb
浏览文件 @
b480da5c
...
...
@@ -39,6 +39,7 @@ module ActionDispatch
autoload
:Rescue
,
'action_dispatch/middleware/rescue'
autoload
:ShowExceptions
,
'action_dispatch/middleware/show_exceptions'
autoload
:Static
,
'action_dispatch/middleware/static'
autoload
:StringCoercion
,
'action_dispatch/middleware/string_coercion'
autoload
:Assertions
,
'action_dispatch/testing/assertions'
autoload
:Integration
,
'action_dispatch/testing/integration'
...
...
actionpack/lib/action_dispatch/middleware/string_coercion.rb
0 → 100644
浏览文件 @
b480da5c
module
ActionDispatch
class
StringCoercion
class
UglyBody
<
ActiveSupport
::
BasicObject
def
initialize
(
body
)
@body
=
body
end
def
each
@body
.
each
do
|
part
|
yield
part
.
to_s
end
end
private
def
method_missing
(
*
args
,
&
block
)
@body
.
__send__
(
*
args
,
&
block
)
end
end
def
initialize
(
app
)
@app
=
app
end
def
call
(
env
)
status
,
headers
,
body
=
@app
.
call
(
env
)
[
status
,
headers
,
UglyBody
.
new
(
body
)]
end
end
end
actionpack/test/abstract_unit.rb
浏览文件 @
b480da5c
...
...
@@ -93,6 +93,7 @@ class ActiveSupport::TestCase
class
ActionController::IntegrationTest
<
ActiveSupport
::
TestCase
def
self
.
build_app
(
routes
=
nil
)
ActionDispatch
::
MiddlewareStack
.
new
{
|
middleware
|
middleware
.
use
"ActionDispatch::StringCoercion"
middleware
.
use
"ActionDispatch::ShowExceptions"
middleware
.
use
"ActionDispatch::Callbacks"
middleware
.
use
"ActionDispatch::ParamsParser"
...
...
actionpack/test/dispatch/string_coercion_test.rb
0 → 100644
浏览文件 @
b480da5c
require
'abstract_unit'
class
StringCoercionTest
<
ActiveSupport
::
TestCase
test
"body responds to each"
do
original_body
=
[]
body
=
ActionDispatch
::
StringCoercion
::
UglyBody
.
new
(
original_body
)
assert
original_body
.
respond_to?
(
:each
)
assert
body
.
respond_to?
(
:each
)
end
test
"body responds to to_path"
do
original_body
=
[]
def
original_body
.
to_path
;
end
body
=
ActionDispatch
::
StringCoercion
::
UglyBody
.
new
(
original_body
)
assert
original_body
.
respond_to?
(
:to_path
)
assert
body
.
respond_to?
(
:to_path
)
end
test
"body does not responds to to_path"
do
original_body
=
[]
body
=
ActionDispatch
::
StringCoercion
::
UglyBody
.
new
(
original_body
)
assert
!
original_body
.
respond_to?
(
:to_path
)
assert
!
body
.
respond_to?
(
:to_path
)
end
test
"calls to_s on body parts"
do
app
=
lambda
{
|
env
|
[
200
,
{
'Content-Type'
=>
'html'
},
[
1
,
2
,
3
]]
}
app
=
ActionDispatch
::
StringCoercion
.
new
(
app
)
parts
=
[]
status
,
headers
,
body
=
app
.
call
({})
body
.
each
{
|
part
|
parts
<<
part
}
assert_equal
%w( 1 2 3 )
,
parts
end
end
railties/lib/rails/initializer.rb
浏览文件 @
b480da5c
...
...
@@ -271,6 +271,7 @@ def self.run(initializer = nil, config = nil)
configuration
.
middleware
.
use
(
ActionDispatch
::
ParamsParser
)
configuration
.
middleware
.
use
(
::
Rack
::
MethodOverride
)
configuration
.
middleware
.
use
(
::
Rack
::
Head
)
configuration
.
middleware
.
use
(
ActionDispatch
::
StringCoercion
)
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录