Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
a9eebde8
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,发现更多精彩内容 >>
提交
a9eebde8
编写于
1月 11, 2010
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of
git://github.com/rails/rails
上级
c1239e65
02bbde4e
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
124 addition
and
200 deletion
+124
-200
actionpack/lib/action_controller/caching/fragments.rb
actionpack/lib/action_controller/caching/fragments.rb
+2
-2
actionpack/lib/action_controller/railtie.rb
actionpack/lib/action_controller/railtie.rb
+25
-3
actionpack/test/template/javascript_helper_test.rb
actionpack/test/template/javascript_helper_test.rb
+5
-0
actionpack/test/template/prototype_helper_test.rb
actionpack/test/template/prototype_helper_test.rb
+5
-0
railties/lib/rails/rack.rb
railties/lib/rails/rack.rb
+0
-1
railties/lib/rails/rack/metal.rb
railties/lib/rails/rack/metal.rb
+0
-59
railties/test/application/metal_test.rb
railties/test/application/metal_test.rb
+86
-0
railties/test/application/middleware_test.rb
railties/test/application/middleware_test.rb
+1
-0
railties/test/fixtures/metal/multiplemetals/app/metal/metal_a.rb
...s/test/fixtures/metal/multiplemetals/app/metal/metal_a.rb
+0
-5
railties/test/fixtures/metal/multiplemetals/app/metal/metal_b.rb
...s/test/fixtures/metal/multiplemetals/app/metal/metal_b.rb
+0
-5
railties/test/fixtures/metal/pluralmetal/app/metal/legacy_routes.rb
...est/fixtures/metal/pluralmetal/app/metal/legacy_routes.rb
+0
-5
railties/test/fixtures/metal/singlemetal/app/metal/foo_metal.rb
...es/test/fixtures/metal/singlemetal/app/metal/foo_metal.rb
+0
-5
railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_a.rb
...est/fixtures/metal/subfolders/app/metal/Folder/metal_a.rb
+0
-7
railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_b.rb
...est/fixtures/metal/subfolders/app/metal/Folder/metal_b.rb
+0
-7
railties/test/metal_test.rb
railties/test/metal_test.rb
+0
-101
未找到文件。
actionpack/lib/action_controller/caching/fragments.rb
浏览文件 @
a9eebde8
...
@@ -36,8 +36,8 @@ def fragment_cache_key(key)
...
@@ -36,8 +36,8 @@ def fragment_cache_key(key)
def
fragment_for
(
buffer
,
name
=
{},
options
=
nil
,
&
block
)
#:nodoc:
def
fragment_for
(
buffer
,
name
=
{},
options
=
nil
,
&
block
)
#:nodoc:
if
perform_caching
if
perform_caching
if
fragment_exist?
(
name
,
options
)
if
fragment_exist?
(
name
,
options
)
buffer
.
concat
(
read_fragment
(
name
,
options
).
html_safe!
)
buffer
.
safe_concat
(
read_fragment
(
name
,
options
)
)
else
else
pos
=
buffer
.
length
pos
=
buffer
.
length
block
.
call
block
.
call
...
...
actionpack/lib/action_controller/railtie.rb
浏览文件 @
a9eebde8
...
@@ -37,11 +37,33 @@ class Railtie < Rails::Railtie
...
@@ -37,11 +37,33 @@ class Railtie < Rails::Railtie
ActionController
::
Base
.
view_paths
=
view_path
if
ActionController
::
Base
.
view_paths
.
blank?
ActionController
::
Base
.
view_paths
=
view_path
if
ActionController
::
Base
.
view_paths
.
blank?
end
end
class
MetalMiddlewareBuilder
def
initialize
(
metals
)
@metals
=
metals
end
def
new
(
app
)
ActionDispatch
::
Cascade
.
new
(
@metals
,
app
)
end
def
name
ActionDispatch
::
Cascade
.
name
end
alias_method
:to_s
,
:name
end
initializer
"action_controller.initialize_metal"
do
|
app
|
initializer
"action_controller.initialize_metal"
do
|
app
|
Rails
::
Rack
::
Metal
.
requested_metals
=
app
.
config
.
metals
metal_root
=
"
#{
Rails
.
root
}
/app/metal"
load_list
=
app
.
config
.
metals
||
Dir
[
"
#{
metal_root
}
/**/*.rb"
]
metals
=
load_list
.
map
{
|
metal
|
metal
=
File
.
basename
(
metal
.
gsub
(
"
#{
metal_root
}
/"
,
''
),
'.rb'
)
require_dependency
metal
metal
.
camelize
.
constantize
}.
compact
app
.
config
.
middleware
.
insert_before
(
:"ActionDispatch::ParamsParser"
,
middleware
=
MetalMiddlewareBuilder
.
new
(
metals
)
Rails
::
Rack
::
Metal
,
:if
=>
Rails
::
Rack
::
Metal
.
metals
.
any?
)
app
.
config
.
middleware
.
insert_before
(
:"ActionDispatch::ParamsParser"
,
middleware
)
end
end
# # Prepare dispatcher callbacks and run 'prepare' callbacks
# # Prepare dispatcher callbacks and run 'prepare' callbacks
...
...
actionpack/test/template/javascript_helper_test.rb
浏览文件 @
a9eebde8
...
@@ -13,8 +13,13 @@ def reset_formats(format)
...
@@ -13,8 +13,13 @@ def reset_formats(format)
def
setup
def
setup
super
super
ActiveSupport
.
escape_html_entities_in_json
=
true
@template
=
self
@template
=
self
end
end
def
teardown
ActiveSupport
.
escape_html_entities_in_json
=
false
end
def
_evaluate_assigns_and_ivars
()
end
def
_evaluate_assigns_and_ivars
()
end
...
...
actionpack/test/template/prototype_helper_test.rb
浏览文件 @
a9eebde8
...
@@ -317,6 +317,11 @@ class JavaScriptGeneratorTest < PrototypeHelperBaseTest
...
@@ -317,6 +317,11 @@ class JavaScriptGeneratorTest < PrototypeHelperBaseTest
def
setup
def
setup
super
super
@generator
=
create_generator
@generator
=
create_generator
ActiveSupport
.
escape_html_entities_in_json
=
true
end
def
teardown
ActiveSupport
.
escape_html_entities_in_json
=
false
end
end
def
_evaluate_assigns_and_ivars
()
end
def
_evaluate_assigns_and_ivars
()
end
...
...
railties/lib/rails/rack.rb
浏览文件 @
a9eebde8
...
@@ -2,7 +2,6 @@ module Rails
...
@@ -2,7 +2,6 @@ module Rails
module
Rack
module
Rack
autoload
:Debugger
,
"rails/rack/debugger"
autoload
:Debugger
,
"rails/rack/debugger"
autoload
:LogTailer
,
"rails/rack/log_tailer"
autoload
:LogTailer
,
"rails/rack/log_tailer"
autoload
:Metal
,
"rails/rack/metal"
autoload
:Static
,
"rails/rack/static"
autoload
:Static
,
"rails/rack/static"
end
end
end
end
railties/lib/rails/rack/metal.rb
已删除
100644 → 0
浏览文件 @
c1239e65
require
'active_support/ordered_hash'
require
'active_support/core_ext/class/attribute_accessors'
require
'active_support/dependencies'
module
Rails
module
Rack
class
Metal
NotFoundResponse
=
[
404
,
{},
[]].
freeze
NotFound
=
lambda
{
NotFoundResponse
}
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/
metal_glob
=
metal_paths
.
map
{
|
base
|
"
#{
base
}
/**/*.rb"
}
all_metals
=
{}
metal_glob
.
each
do
|
glob
|
Dir
[
glob
].
sort
.
map
do
|
file
|
file
=
file
.
match
(
matcher
)[
1
]
all_metals
[
file
.
camelize
]
=
file
end
end
load_list
=
requested_metals
||
all_metals
.
keys
load_list
.
map
do
|
requested_metal
|
if
metal
=
all_metals
[
requested_metal
]
require_dependency
metal
requested_metal
.
constantize
end
end
.
compact
end
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
end
def
call
(
env
)
@metals
.
keys
.
each
do
|
app
|
result
=
app
.
call
(
env
)
return
result
unless
@pass_through_on
.
include?
(
result
[
0
].
to_i
)
end
@app
.
call
(
env
)
end
end
end
end
railties/test/application/metal_test.rb
0 → 100644
浏览文件 @
a9eebde8
require
'isolation/abstract_unit'
module
ApplicationTests
class
MetalTest
<
Test
::
Unit
::
TestCase
include
ActiveSupport
::
Testing
::
Isolation
def
setup
build_app
boot_rails
require
'rack/test'
extend
Rack
::
Test
::
Methods
end
def
app
@app
||=
begin
require
"
#{
app_path
}
/config/environment"
Rails
.
application
end
end
test
"single metal endpoint"
do
app_file
'app/metal/foo_metal.rb'
,
<<-
RUBY
class FooMetal
def self.call(env)
[200, { "Content-Type" => "text/html"}, ["FooMetal"]]
end
end
RUBY
get
"/"
assert_equal
200
,
last_response
.
status
assert_equal
"FooMetal"
,
last_response
.
body
end
test
"multiple metal endpoints"
do
app_file
'app/metal/metal_a.rb'
,
<<-
RUBY
class MetalA
def self.call(env)
[404, { "Content-Type" => "text/html", "X-Cascade" => "pass" }, ["Metal A"]]
end
end
RUBY
app_file
'app/metal/metal_b.rb'
,
<<-
RUBY
class MetalB
def self.call(env)
[200, { "Content-Type" => "text/html"}, ["Metal B"]]
end
end
RUBY
get
"/"
assert_equal
200
,
last_response
.
status
assert_equal
"Metal B"
,
last_response
.
body
end
test
"pass through to application"
do
app_file
'app/metal/foo_metal.rb'
,
<<-
RUBY
class FooMetal
def self.call(env)
[404, { "Content-Type" => "text/html", "X-Cascade" => "pass" }, ["Not Found"]]
end
end
RUBY
controller
:foo
,
<<-
RUBY
class FooController < ActionController::Base
def index
render :text => "foo"
end
end
RUBY
app_file
'config/routes.rb'
,
<<-
RUBY
AppTemplate::Application.routes.draw do |map|
match ':controller(/:action)'
end
RUBY
get
"/foo"
assert_equal
200
,
last_response
.
status
assert_equal
"foo"
,
last_response
.
body
end
end
end
railties/test/application/middleware_test.rb
浏览文件 @
a9eebde8
...
@@ -20,6 +20,7 @@ def setup
...
@@ -20,6 +20,7 @@ def setup
"ActionDispatch::ShowExceptions"
,
"ActionDispatch::ShowExceptions"
,
"ActionDispatch::Callbacks"
,
"ActionDispatch::Callbacks"
,
"ActionDispatch::Session::CookieStore"
,
"ActionDispatch::Session::CookieStore"
,
"ActionDispatch::Cascade"
,
"ActionDispatch::ParamsParser"
,
"ActionDispatch::ParamsParser"
,
"Rack::MethodOverride"
,
"Rack::MethodOverride"
,
"Rack::Head"
,
"Rack::Head"
,
...
...
railties/test/fixtures/metal/multiplemetals/app/metal/metal_a.rb
已删除
100644 → 0
浏览文件 @
c1239e65
class
MetalA
def
self
.
call
(
env
)
[
404
,
{
"Content-Type"
=>
"text/html"
},
[
"Metal A"
]]
end
end
railties/test/fixtures/metal/multiplemetals/app/metal/metal_b.rb
已删除
100644 → 0
浏览文件 @
c1239e65
class
MetalB
def
self
.
call
(
env
)
[
200
,
{
"Content-Type"
=>
"text/html"
},
[
"Metal B"
]]
end
end
railties/test/fixtures/metal/pluralmetal/app/metal/legacy_routes.rb
已删除
100644 → 0
浏览文件 @
c1239e65
class
LegacyRoutes
<
Rails
::
Rack
::
Metal
def
self
.
call
(
env
)
[
301
,
{
"Location"
=>
"http://example.com"
},
[]]
end
end
railties/test/fixtures/metal/singlemetal/app/metal/foo_metal.rb
已删除
100644 → 0
浏览文件 @
c1239e65
class
FooMetal
<
Rails
::
Rack
::
Metal
def
self
.
call
(
env
)
[
200
,
{
"Content-Type"
=>
"text/html"
},
[
"Hi"
]]
end
end
railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_a.rb
已删除
100644 → 0
浏览文件 @
c1239e65
module
Folder
class
MetalA
<
Rails
::
Rack
::
Metal
def
self
.
call
(
env
)
[
200
,
{
"Content-Type"
=>
"text/html"
},
[
"Hi"
]]
end
end
end
railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_b.rb
已删除
100644 → 0
浏览文件 @
c1239e65
module
Folder
class
MetalB
<
Rails
::
Rack
::
Metal
def
self
.
call
(
env
)
[
200
,
{
"Content-Type"
=>
"text/html"
},
[
"Hi"
]]
end
end
end
railties/test/metal_test.rb
已删除
100644 → 0
浏览文件 @
c1239e65
require
'abstract_unit'
class
MetalTest
<
Test
::
Unit
::
TestCase
def
test_metals_should_return_list_of_found_metal_apps
use_appdir
(
"singlemetal"
)
do
assert_equal
([
"FooMetal"
],
found_metals_as_string_array
)
end
end
def
test_metals_should_respect_class_name_conventions
use_appdir
(
"pluralmetal"
)
do
assert_equal
([
"LegacyRoutes"
],
found_metals_as_string_array
)
end
end
def
test_metals_should_return_alphabetical_list_of_found_metal_apps
use_appdir
(
"multiplemetals"
)
do
assert_equal
([
"MetalA"
,
"MetalB"
],
found_metals_as_string_array
)
end
end
def
test_metals_load_order_should_be_overriden_by_requested_metals
use_appdir
(
"multiplemetals"
)
do
Rails
::
Rack
::
Metal
.
requested_metals
=
[
"MetalB"
,
"MetalA"
]
assert_equal
([
"MetalB"
,
"MetalA"
],
found_metals_as_string_array
)
end
end
def
test_metals_not_listed_should_not_load
use_appdir
(
"multiplemetals"
)
do
Rails
::
Rack
::
Metal
.
requested_metals
=
[
"MetalB"
]
assert_equal
([
"MetalB"
],
found_metals_as_string_array
)
end
end
def
test_metal_finding_should_work_with_subfolders
use_appdir
(
"subfolders"
)
do
assert_equal
([
"Folder::MetalA"
,
"Folder::MetalB"
],
found_metals_as_string_array
)
end
end
def
test_metal_finding_with_requested_metals_should_work_with_subfolders
use_appdir
(
"subfolders"
)
do
Rails
::
Rack
::
Metal
.
requested_metals
=
[
"Folder::MetalB"
]
assert_equal
([
"Folder::MetalB"
],
found_metals_as_string_array
)
end
end
def
test_metal_finding_should_work_with_multiple_metal_paths_in_185_and_below
use_appdir
(
"singlemetal"
)
do
engine_metal_path
=
"
#{
File
.
dirname
(
__FILE__
)
}
/fixtures/plugins/engines/engine/app/metal"
Rails
::
Rack
::
Metal
.
metal_paths
<<
engine_metal_path
$LOAD_PATH
<<
engine_metal_path
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
{
|
env
|
[
402
,{},[
"End of the Line"
]]}
end
def
use_appdir
(
root
)
dir
=
"
#{
File
.
dirname
(
__FILE__
)
}
/fixtures/metal/
#{
root
}
"
Rails
::
Rack
::
Metal
.
metal_paths
=
[
"
#{
dir
}
/app/metal"
]
Rails
::
Rack
::
Metal
.
requested_metals
=
nil
$LOAD_PATH
<<
"
#{
dir
}
/app/metal"
yield
end
def
found_metals_as_string_array
Rails
::
Rack
::
Metal
.
metals
.
map
{
|
m
|
m
.
to_s
}
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录