Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
6f0c9cdd
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,发现更多精彩内容 >>
提交
6f0c9cdd
编写于
5月 18, 2012
作者:
P
Piotr Sarnacki
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6391 from strzalek/redirect_route_inspect
Redirect route inspect
上级
40bdf553
5f7bfb77
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
33 addition
and
28 deletion
+33
-28
actionpack/lib/action_dispatch/routing/redirection.rb
actionpack/lib/action_dispatch/routing/redirection.rb
+4
-0
railties/lib/rails/application/route_inspector.rb
railties/lib/rails/application/route_inspector.rb
+2
-2
railties/test/application/route_inspect_test.rb
railties/test/application/route_inspect_test.rb
+27
-26
未找到文件。
actionpack/lib/action_dispatch/routing/redirection.rb
浏览文件 @
6f0c9cdd
...
...
@@ -35,6 +35,10 @@ def call(env)
def
path
(
params
,
request
)
block
.
call
params
,
request
end
def
inspect
"Redirect (
#{
status
}
)"
end
end
class
OptionRedirect
<
Redirect
# :nodoc:
...
...
railties/lib/rails/application/route_inspector.rb
浏览文件 @
6f0c9cdd
...
...
@@ -16,7 +16,7 @@ def rack_app(app = self.app)
class_name
=
app
.
class
.
name
.
to_s
if
class_name
==
"ActionDispatch::Routing::Mapper::Constraints"
rack_app
(
app
.
app
)
elsif
class_name
!~
/^ActionDispatch::Routing/
elsif
class_name
==
"ActionDispatch::Routing::Redirect"
||
class_name
!~
/^ActionDispatch::Routing/
app
end
end
...
...
@@ -67,7 +67,7 @@ def initialize
@engines
=
Hash
.
new
end
def
format
all_routes
,
filter
=
nil
def
format
(
all_routes
,
filter
=
nil
)
if
filter
all_routes
=
all_routes
.
select
{
|
route
|
route
.
defaults
[
:controller
]
==
filter
}
end
...
...
railties/test/application/route_inspect_test.rb
浏览文件 @
6f0c9cdd
...
...
@@ -16,6 +16,11 @@ def setup
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
...
...
@@ -26,12 +31,11 @@ def self.to_s
get
'/cart'
,
:to
=>
'cart#show'
end
@set
.
draw
do
output
=
draw
do
get
'/custom/assets'
,
:to
=>
'custom_assets#show'
mount
engine
=>
"/blog"
,
:as
=>
"blog"
end
output
=
@inspector
.
format
@set
.
routes
expected
=
[
"custom_assets GET /custom/assets(.:format) custom_assets#show"
,
" blog /blog Blog::Engine"
,
...
...
@@ -42,26 +46,23 @@ def self.to_s
end
def
test_cart_inspect
@set
.
draw
do
output
=
draw
do
get
'/cart'
,
:to
=>
'cart#show'
end
output
=
@inspector
.
format
@set
.
routes
assert_equal
[
"cart GET /cart(.:format) cart#show"
],
output
end
def
test_inspect_shows_custom_assets
@set
.
draw
do
output
=
draw
do
get
'/custom/assets'
,
:to
=>
'custom_assets#show'
end
output
=
@inspector
.
format
@set
.
routes
assert_equal
[
"custom_assets GET /custom/assets(.:format) custom_assets#show"
],
output
end
def
test_inspect_routes_shows_resources_route
@set
.
draw
do
output
=
draw
do
resources
:articles
end
output
=
@inspector
.
format
@set
.
routes
expected
=
[
" articles GET /articles(.:format) articles#index"
,
" POST /articles(.:format) articles#create"
,
...
...
@@ -75,50 +76,44 @@ def test_inspect_routes_shows_resources_route
end
def
test_inspect_routes_shows_root_route
@set
.
draw
do
output
=
draw
do
root
:to
=>
'pages#main'
end
output
=
@inspector
.
format
@set
.
routes
assert_equal
[
"root GET / pages#main"
],
output
end
def
test_inspect_routes_shows_dynamic_action_route
@set
.
draw
do
output
=
draw
do
get
'api/:action'
=>
'api'
end
output
=
@inspector
.
format
@set
.
routes
assert_equal
[
" GET /api/:action(.:format) api#:action"
],
output
end
def
test_inspect_routes_shows_controller_and_action_only_route
@set
.
draw
do
output
=
draw
do
get
':controller/:action'
end
output
=
@inspector
.
format
@set
.
routes
assert_equal
[
" GET /:controller/:action(.:format) :controller#:action"
],
output
end
def
test_inspect_routes_shows_controller_and_action_route_with_constraints
@set
.
draw
do
output
=
draw
do
get
':controller(/:action(/:id))'
,
:id
=>
/\d+/
end
output
=
@inspector
.
format
@set
.
routes
assert_equal
[
" GET /:controller(/:action(/:id))(.:format) :controller#:action {:id=>/
\\
d+/}"
],
output
end
def
test_rake_routes_shows_route_with_defaults
@set
.
draw
do
output
=
draw
do
get
'photos/:id'
=>
'photos#show'
,
:defaults
=>
{
:format
=>
'jpg'
}
end
output
=
@inspector
.
format
@set
.
routes
assert_equal
[
%Q[ GET /photos/:id(.:format) photos#show {:format=>"jpg"}]
],
output
end
def
test_rake_routes_shows_route_with_constraints
@set
.
draw
do
output
=
draw
do
get
'photos/:id'
=>
'photos#show'
,
:id
=>
/[A-Z]\d{5}/
end
output
=
@inspector
.
format
@set
.
routes
assert_equal
[
" GET /photos/:id(.:format) photos#show {:id=>/[A-Z]
\\
d{5}/}"
],
output
end
...
...
@@ -128,10 +123,9 @@ def self.call(env)
end
def
test_rake_routes_shows_route_with_rack_app
@set
.
draw
do
output
=
draw
do
get
'foo/:id'
=>
RackApp
,
:id
=>
/[A-Z]\d{5}/
end
output
=
@inspector
.
format
@set
.
routes
assert_equal
[
" GET /foo/:id(.:format)
#{
RackApp
.
name
}
{:id=>/[A-Z]
\\
d{5}/}"
],
output
end
...
...
@@ -142,23 +136,30 @@ def to_s
end
end
@set
.
draw
do
output
=
draw
do
scope
:constraint
=>
constraint
.
new
do
mount
RackApp
=>
'/foo'
end
end
output
=
@inspector
.
format
@set
.
routes
assert_equal
[
" /foo
#{
RackApp
.
name
}
{:constraint=>( my custom constraint )}"
],
output
end
def
test_rake_routes_dont_show_app_mounted_in_assets_prefix
@set
.
draw
do
output
=
draw
do
get
'/sprockets'
=>
RackApp
end
output
=
@inspector
.
format
@set
.
routes
assert_no_match
(
/RackApp/
,
output
.
first
)
assert_no_match
(
/\/sprockets/
,
output
.
first
)
end
def
test_redirect
output
=
draw
do
match
'/foo'
=>
redirect
(
"/bar"
)
match
'/foo2'
=>
redirect
(
"/bar"
,
status:
307
)
end
assert_equal
" foo /foo(.:format) Redirect (301)"
,
output
[
0
]
assert_equal
"foo2 /foo2(.:format) Redirect (307)"
,
output
[
1
]
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录