Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
3e871eee
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,发现更多精彩内容 >>
提交
3e871eee
编写于
8月 18, 2010
作者:
J
Javier Martín
提交者:
Santiago Pastorino
8月 18, 2010
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Don't pluralize resource methods [#4704 state:resolved]
Signed-off-by:
N
Santiago Pastorino
<
santiago@wyeworks.com
>
上级
cad8bef5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
76 addition
and
14 deletion
+76
-14
actionpack/lib/action_dispatch/routing/mapper.rb
actionpack/lib/action_dispatch/routing/mapper.rb
+14
-14
actionpack/test/dispatch/routing_test.rb
actionpack/test/dispatch/routing_test.rb
+62
-0
未找到文件。
actionpack/lib/action_dispatch/routing/mapper.rb
浏览文件 @
3e871eee
...
@@ -498,16 +498,14 @@ def name
...
@@ -498,16 +498,14 @@ def name
end
end
def
plural
def
plural
name
.
to_s
.
pluralize
@plural
||=
name
.
to_s
end
end
def
singular
def
singular
name
.
to_s
.
singularize
@singular
||=
name
.
to_s
.
singularize
end
end
def
member_name
alias
:member_name
:singular
singular
end
# Checks for uncountable plurals, and appends "_index" if they're.
# Checks for uncountable plurals, and appends "_index" if they're.
def
collection_name
def
collection_name
...
@@ -518,9 +516,7 @@ def resource_scope
...
@@ -518,9 +516,7 @@ def resource_scope
{
:controller
=>
controller
}
{
:controller
=>
controller
}
end
end
def
collection_scope
alias
:collection_scope
:path
path
end
def
member_scope
def
member_scope
"
#{
path
}
/:id"
"
#{
path
}
/:id"
...
@@ -547,15 +543,19 @@ def initialize(entities, options)
...
@@ -547,15 +543,19 @@ def initialize(entities, options)
@options
=
options
@options
=
options
end
end
def
member_name
def
plural
nam
e
@plural
||=
name
.
to_s
.
pluraliz
e
end
end
alias
:collection_name
:member_name
def
member_scope
def
singular
path
@singular
||=
name
.
to_s
end
end
alias
:nested_scope
:member_scope
alias
:member_name
:singular
alias
:collection_name
:singular
alias
:member_scope
:path
alias
:nested_scope
:path
end
end
def
initialize
(
*
args
)
#:nodoc:
def
initialize
(
*
args
)
#:nodoc:
...
...
actionpack/test/dispatch/routing_test.rb
浏览文件 @
3e871eee
...
@@ -337,6 +337,14 @@ def self.matches?(request)
...
@@ -337,6 +337,14 @@ def self.matches?(request)
resources
:content
resources
:content
namespace
:transport
do
resources
:taxis
end
namespace
:medical
do
resource
:taxis
end
scope
:constraints
=>
{
:id
=>
/\d+/
}
do
scope
:constraints
=>
{
:id
=>
/\d+/
}
do
get
'/tickets'
,
:to
=>
'tickets#index'
,
:as
=>
:tickets
get
'/tickets'
,
:to
=>
'tickets#index'
,
:as
=>
:tickets
end
end
...
@@ -1884,6 +1892,60 @@ def test_only_scope_should_override_parent_except_scope
...
@@ -1884,6 +1892,60 @@ def test_only_scope_should_override_parent_except_scope
end
end
end
end
def
test_resources_are_not_pluralized
with_test_routes
do
get
'/transport/taxis'
assert_equal
'transport/taxis#index'
,
@response
.
body
assert_equal
'/transport/taxis'
,
transport_taxis_path
get
'/transport/taxis/new'
assert_equal
'transport/taxis#new'
,
@response
.
body
assert_equal
'/transport/taxis/new'
,
new_transport_taxi_path
post
'/transport/taxis'
assert_equal
'transport/taxis#create'
,
@response
.
body
get
'/transport/taxis/1'
assert_equal
'transport/taxis#show'
,
@response
.
body
assert_equal
'/transport/taxis/1'
,
transport_taxi_path
(
:id
=>
'1'
)
get
'/transport/taxis/1/edit'
assert_equal
'transport/taxis#edit'
,
@response
.
body
assert_equal
'/transport/taxis/1/edit'
,
edit_transport_taxi_path
(
:id
=>
'1'
)
put
'/transport/taxis/1'
assert_equal
'transport/taxis#update'
,
@response
.
body
delete
'/transport/taxis/1'
assert_equal
'transport/taxis#destroy'
,
@response
.
body
end
end
def
test_singleton_resources_are_not_singularized
with_test_routes
do
get
'/medical/taxis/new'
assert_equal
'medical/taxes#new'
,
@response
.
body
assert_equal
'/medical/taxis/new'
,
new_medical_taxis_path
post
'/medical/taxis'
assert_equal
'medical/taxes#create'
,
@response
.
body
get
'/medical/taxis'
assert_equal
'medical/taxes#show'
,
@response
.
body
assert_equal
'/medical/taxis'
,
medical_taxis_path
get
'/medical/taxis/edit'
assert_equal
'medical/taxes#edit'
,
@response
.
body
assert_equal
'/medical/taxis/edit'
,
edit_medical_taxis_path
put
'/medical/taxis'
assert_equal
'medical/taxes#update'
,
@response
.
body
delete
'/medical/taxis'
assert_equal
'medical/taxes#destroy'
,
@response
.
body
end
end
private
private
def
with_test_routes
def
with_test_routes
yield
yield
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录