Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
0c68d23f
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,发现更多精彩内容 >>
提交
0c68d23f
编写于
7月 22, 2009
作者:
J
John Duff
提交者:
Joshua Peek
7月 22, 2009
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make pass through error code configurable [#2817 state:resolved]
Signed-off-by:
N
Joshua Peek
<
josh@joshpeek.com
>
上级
272c504f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
41 addition
and
5 deletion
+41
-5
railties/lib/rails/rack/metal.rb
railties/lib/rails/rack/metal.rb
+7
-1
railties/test/fixtures/metal/multiplemetals/app/metal/metal_a.rb
...s/test/fixtures/metal/multiplemetals/app/metal/metal_a.rb
+2
-2
railties/test/fixtures/metal/multiplemetals/app/metal/metal_b.rb
...s/test/fixtures/metal/multiplemetals/app/metal/metal_b.rb
+2
-2
railties/test/metal_test.rb
railties/test/metal_test.rb
+30
-0
未找到文件。
railties/lib/rails/rack/metal.rb
浏览文件 @
0c68d23f
...
...
@@ -11,6 +11,9 @@ class Metal
cattr_accessor
:metal_paths
self
.
metal_paths
=
[
"
#{
Rails
.
root
}
/app/metal"
]
cattr_accessor
:requested_metals
cattr_accessor
:pass_through_on
self
.
pass_through_on
=
404
def
self
.
metals
matcher
=
/
#{
Regexp
.
escape
(
'/app/metal/'
)
}
(.*)\.rb\Z/
...
...
@@ -36,6 +39,9 @@ def self.metals
def
initialize
(
app
)
@app
=
app
@pass_through_on
=
{}
[
*
self
.
class
.
pass_through_on
].
each
{
|
status
|
@pass_through_on
[
status
]
=
true
}
@metals
=
ActiveSupport
::
OrderedHash
.
new
self
.
class
.
metals
.
each
{
|
app
|
@metals
[
app
]
=
true
}
freeze
...
...
@@ -44,7 +50,7 @@ def initialize(app)
def
call
(
env
)
@metals
.
keys
.
each
do
|
app
|
result
=
app
.
call
(
env
)
return
result
unless
result
[
0
].
to_i
==
404
return
result
unless
@pass_through_on
.
include?
(
result
[
0
].
to_i
)
end
@app
.
call
(
env
)
end
...
...
railties/test/fixtures/metal/multiplemetals/app/metal/metal_a.rb
浏览文件 @
0c68d23f
class
MetalA
<
Rails
::
Rack
::
Metal
class
MetalA
def
self
.
call
(
env
)
[
200
,
{
"Content-Type"
=>
"text/html"
},
[
"Hi
"
]]
[
404
,
{
"Content-Type"
=>
"text/html"
},
[
"Metal A
"
]]
end
end
railties/test/fixtures/metal/multiplemetals/app/metal/metal_b.rb
浏览文件 @
0c68d23f
class
MetalB
<
Rails
::
Rack
::
Metal
class
MetalB
def
self
.
call
(
env
)
[
200
,
{
"Content-Type"
=>
"text/html"
},
[
"
Hi
"
]]
[
200
,
{
"Content-Type"
=>
"text/html"
},
[
"
Metal B
"
]]
end
end
railties/test/metal_test.rb
浏览文件 @
0c68d23f
...
...
@@ -55,8 +55,38 @@ def test_metal_finding_should_work_with_multiple_metal_paths_in_185_and_below
assert_equal
([
"FooMetal"
,
"EngineMetal"
],
found_metals_as_string_array
)
end
end
def
test_metal_default_pass_through_on_404
use_appdir
(
"multiplemetals"
)
do
result
=
Rails
::
Rack
::
Metal
.
new
(
app
).
call
({})
assert_equal
200
,
result
.
first
assert_equal
[
"Metal B"
],
result
.
last
end
end
def
test_metal_pass_through_on_417
use_appdir
(
"multiplemetals"
)
do
Rails
::
Rack
::
Metal
.
pass_through_on
=
417
result
=
Rails
::
Rack
::
Metal
.
new
(
app
).
call
({})
assert_equal
404
,
result
.
first
assert_equal
[
"Metal A"
],
result
.
last
end
end
def
test_metal_pass_through_on_404_and_200
use_appdir
(
"multiplemetals"
)
do
Rails
::
Rack
::
Metal
.
pass_through_on
=
[
404
,
200
]
result
=
Rails
::
Rack
::
Metal
.
new
(
app
).
call
({})
assert_equal
402
,
result
.
first
assert_equal
[
"End of the Line"
],
result
.
last
end
end
private
def
app
lambda
{[
402
,{},[
"End of the Line"
]]}
end
def
use_appdir
(
root
)
dir
=
"
#{
File
.
dirname
(
__FILE__
)
}
/fixtures/metal/
#{
root
}
"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录