Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
21c5bc92
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,发现更多精彩内容 >>
提交
21c5bc92
编写于
7月 08, 2012
作者:
C
Carlos Antonio da Silva
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove RoutesInspector from railties, since it was moved to AP
Changes introduced in
7404cda9
. Fix railties build.
上级
15d80ebb
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
0 addition
and
290 deletion
+0
-290
railties/lib/rails/application/routes_inspector.rb
railties/lib/rails/application/routes_inspector.rb
+0
-121
railties/lib/rails/info_controller.rb
railties/lib/rails/info_controller.rb
+0
-1
railties/test/application/routes_inspect_test.rb
railties/test/application/routes_inspect_test.rb
+0
-168
未找到文件。
railties/lib/rails/application/routes_inspector.rb
已删除
100644 → 0
浏览文件 @
15d80ebb
require
'delegate'
module
Rails
class
Application
class
RouteWrapper
<
SimpleDelegator
def
endpoint
rack_app
?
rack_app
.
inspect
:
"
#{
controller
}
#
#{
action
}
"
end
def
constraints
requirements
.
except
(
:controller
,
:action
)
end
def
rack_app
(
app
=
self
.
app
)
@rack_app
||=
begin
class_name
=
app
.
class
.
name
.
to_s
if
class_name
==
"ActionDispatch::Routing::Mapper::Constraints"
rack_app
(
app
.
app
)
elsif
ActionDispatch
::
Routing
::
Redirect
===
app
||
class_name
!~
/^ActionDispatch::Routing/
app
end
end
end
def
verb
super
.
source
.
gsub
(
/[$^]/
,
''
)
end
def
path
super
.
spec
.
to_s
end
def
name
super
.
to_s
end
def
reqs
@reqs
||=
begin
reqs
=
endpoint
reqs
+=
"
#{
constraints
.
inspect
}
"
unless
constraints
.
empty?
reqs
end
end
def
controller
requirements
[
:controller
]
||
':controller'
end
def
action
requirements
[
:action
]
||
':action'
end
def
internal?
path
=~
%r{/rails/info.*|^
#{
Rails
.
application
.
config
.
assets
.
prefix
}
}
end
def
engine?
rack_app
&&
rack_app
.
respond_to?
(
:routes
)
end
end
##
# This class is just used for displaying route information when someone
# executes `rake routes`. People should not use this class.
class
RoutesInspector
# :nodoc:
def
initialize
@engines
=
Hash
.
new
end
def
format
(
all_routes
,
filter
=
nil
)
if
filter
all_routes
=
all_routes
.
select
{
|
route
|
route
.
defaults
[
:controller
]
==
filter
}
end
routes
=
collect_routes
(
all_routes
)
formatted_routes
(
routes
)
+
formatted_routes_for_engines
end
def
collect_routes
(
routes
)
routes
=
routes
.
collect
do
|
route
|
RouteWrapper
.
new
(
route
)
end
.
reject
do
|
route
|
route
.
internal?
end
.
collect
do
|
route
|
collect_engine_routes
(
route
)
{
:name
=>
route
.
name
,
:verb
=>
route
.
verb
,
:path
=>
route
.
path
,
:reqs
=>
route
.
reqs
}
end
end
def
collect_engine_routes
(
route
)
name
=
route
.
endpoint
return
unless
route
.
engine?
return
if
@engines
[
name
]
routes
=
route
.
rack_app
.
routes
if
routes
.
is_a?
(
ActionDispatch
::
Routing
::
RouteSet
)
@engines
[
name
]
=
collect_routes
(
routes
.
routes
)
end
end
def
formatted_routes_for_engines
@engines
.
map
do
|
name
,
routes
|
[
"
\n
Routes for
#{
name
}
:"
]
+
formatted_routes
(
routes
)
end
.
flatten
end
def
formatted_routes
(
routes
)
name_width
=
routes
.
map
{
|
r
|
r
[
:name
].
length
}.
max
verb_width
=
routes
.
map
{
|
r
|
r
[
:verb
].
length
}.
max
path_width
=
routes
.
map
{
|
r
|
r
[
:path
].
length
}.
max
routes
.
map
do
|
r
|
"
#{
r
[
:name
].
rjust
(
name_width
)
}
#{
r
[
:verb
].
ljust
(
verb_width
)
}
#{
r
[
:path
].
ljust
(
path_width
)
}
#{
r
[
:reqs
]
}
"
end
end
end
end
end
railties/lib/rails/info_controller.rb
浏览文件 @
21c5bc92
...
...
@@ -15,7 +15,6 @@ def properties
end
def
routes
inspector
=
Rails
::
Application
::
RoutesInspector
.
new
inspector
=
ActionDispatch
::
Routing
::
RouteInspector
.
new
@info
=
inspector
.
format
(
_routes
.
routes
).
join
(
"
\n
"
)
end
...
...
railties/test/application/routes_inspect_test.rb
已删除
100644 → 0
浏览文件 @
15d80ebb
require
'minitest/autorun'
require
'rails/application/routes_inspector'
require
'action_controller'
require
'rails/engine'
module
ApplicationTests
class
RoutesInspectTest
<
ActiveSupport
::
TestCase
def
setup
@set
=
ActionDispatch
::
Routing
::
RouteSet
.
new
@inspector
=
Rails
::
Application
::
RoutesInspector
.
new
app
=
ActiveSupport
::
OrderedOptions
.
new
app
.
config
=
ActiveSupport
::
OrderedOptions
.
new
app
.
config
.
assets
=
ActiveSupport
::
OrderedOptions
.
new
app
.
config
.
assets
.
prefix
=
'/sprockets'
Rails
.
stubs
(
:application
).
returns
(
app
)
Rails
.
stubs
(
:env
).
returns
(
"development"
)
end
def
draw
(
&
block
)
@set
.
draw
(
&
block
)
@inspector
.
format
(
@set
.
routes
)
end
def
test_displaying_routes_for_engines
engine
=
Class
.
new
(
Rails
::
Engine
)
do
def
self
.
to_s
"Blog::Engine"
end
end
engine
.
routes
.
draw
do
get
'/cart'
,
:to
=>
'cart#show'
end
output
=
draw
do
get
'/custom/assets'
,
:to
=>
'custom_assets#show'
mount
engine
=>
"/blog"
,
:as
=>
"blog"
end
expected
=
[
"custom_assets GET /custom/assets(.:format) custom_assets#show"
,
" blog /blog Blog::Engine"
,
"
\n
Routes for Blog::Engine:"
,
"cart GET /cart(.:format) cart#show"
]
assert_equal
expected
,
output
end
def
test_cart_inspect
output
=
draw
do
get
'/cart'
,
:to
=>
'cart#show'
end
assert_equal
[
"cart GET /cart(.:format) cart#show"
],
output
end
def
test_inspect_shows_custom_assets
output
=
draw
do
get
'/custom/assets'
,
:to
=>
'custom_assets#show'
end
assert_equal
[
"custom_assets GET /custom/assets(.:format) custom_assets#show"
],
output
end
def
test_inspect_routes_shows_resources_route
output
=
draw
do
resources
:articles
end
expected
=
[
" articles GET /articles(.:format) articles#index"
,
" POST /articles(.:format) articles#create"
,
" new_article GET /articles/new(.:format) articles#new"
,
"edit_article GET /articles/:id/edit(.:format) articles#edit"
,
" article GET /articles/:id(.:format) articles#show"
,
" PATCH /articles/:id(.:format) articles#update"
,
" PUT /articles/:id(.:format) articles#update"
,
" DELETE /articles/:id(.:format) articles#destroy"
]
assert_equal
expected
,
output
end
def
test_inspect_routes_shows_root_route
output
=
draw
do
root
:to
=>
'pages#main'
end
assert_equal
[
"root GET / pages#main"
],
output
end
def
test_inspect_routes_shows_dynamic_action_route
output
=
draw
do
get
'api/:action'
=>
'api'
end
assert_equal
[
" GET /api/:action(.:format) api#:action"
],
output
end
def
test_inspect_routes_shows_controller_and_action_only_route
output
=
draw
do
get
':controller/:action'
end
assert_equal
[
" GET /:controller/:action(.:format) :controller#:action"
],
output
end
def
test_inspect_routes_shows_controller_and_action_route_with_constraints
output
=
draw
do
get
':controller(/:action(/:id))'
,
:id
=>
/\d+/
end
assert_equal
[
" GET /:controller(/:action(/:id))(.:format) :controller#:action {:id=>/
\\
d+/}"
],
output
end
def
test_rake_routes_shows_route_with_defaults
output
=
draw
do
get
'photos/:id'
=>
'photos#show'
,
:defaults
=>
{
:format
=>
'jpg'
}
end
assert_equal
[
%Q[ GET /photos/:id(.:format) photos#show {:format=>"jpg"}]
],
output
end
def
test_rake_routes_shows_route_with_constraints
output
=
draw
do
get
'photos/:id'
=>
'photos#show'
,
:id
=>
/[A-Z]\d{5}/
end
assert_equal
[
" GET /photos/:id(.:format) photos#show {:id=>/[A-Z]
\\
d{5}/}"
],
output
end
class
RackApp
def
self
.
call
(
env
)
end
end
def
test_rake_routes_shows_route_with_rack_app
output
=
draw
do
get
'foo/:id'
=>
RackApp
,
:id
=>
/[A-Z]\d{5}/
end
assert_equal
[
" GET /foo/:id(.:format)
#{
RackApp
.
name
}
{:id=>/[A-Z]
\\
d{5}/}"
],
output
end
def
test_rake_routes_shows_route_with_rack_app_nested_with_dynamic_constraints
constraint
=
Class
.
new
do
def
to_s
"( my custom constraint )"
end
end
output
=
draw
do
scope
:constraint
=>
constraint
.
new
do
mount
RackApp
=>
'/foo'
end
end
assert_equal
[
" /foo
#{
RackApp
.
name
}
{:constraint=>( my custom constraint )}"
],
output
end
def
test_rake_routes_dont_show_app_mounted_in_assets_prefix
output
=
draw
do
get
'/sprockets'
=>
RackApp
end
assert_no_match
(
/RackApp/
,
output
.
first
)
assert_no_match
(
/\/sprockets/
,
output
.
first
)
end
def
test_redirect
output
=
draw
do
get
"/foo"
=>
redirect
(
"/foo/bar"
),
:constraints
=>
{
:subdomain
=>
"admin"
}
get
"/bar"
=>
redirect
(
path:
"/foo/bar"
,
status:
307
)
get
"/foobar"
=>
redirect
{
"/foo/bar"
}
end
assert_equal
" foo GET /foo(.:format) redirect(301, /foo/bar) {:subdomain=>
\"
admin
\"
}"
,
output
[
0
]
assert_equal
" bar GET /bar(.:format) redirect(307, path: /foo/bar)"
,
output
[
1
]
assert_equal
"foobar GET /foobar(.:format) redirect(301)"
,
output
[
2
]
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录