Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
d771e7d1
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,发现更多精彩内容 >>
提交
d771e7d1
编写于
3月 11, 2009
作者:
M
Mike Gunderloy
提交者:
Pratik Naik
3月 12, 2009
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Handle irregular plurals in polymorphic_urls [#2212 state:resolved]
Signed-off-by:
N
Pratik Naik
<
pratiknaik@gmail.com
>
上级
3c64c9a5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
90 addition
and
2 deletion
+90
-2
actionpack/lib/action_controller/polymorphic_routes.rb
actionpack/lib/action_controller/polymorphic_routes.rb
+5
-2
actionpack/test/controller/polymorphic_routes_test.rb
actionpack/test/controller/polymorphic_routes_test.rb
+85
-0
未找到文件。
actionpack/lib/action_controller/polymorphic_routes.rb
浏览文件 @
d771e7d1
...
...
@@ -163,7 +163,8 @@ def build_named_route_call(records, namespace, inflection, options = {})
if
parent
.
is_a?
(
Symbol
)
||
parent
.
is_a?
(
String
)
string
<<
"
#{
parent
}
_"
else
string
<<
"
#{
RecordIdentifier
.
__send__
(
"singular_class_name"
,
parent
)
}
_"
string
<<
"
#{
RecordIdentifier
.
__send__
(
"plural_class_name"
,
parent
)
}
"
.
singularize
string
<<
"_"
end
end
end
...
...
@@ -171,7 +172,9 @@ def build_named_route_call(records, namespace, inflection, options = {})
if
record
.
is_a?
(
Symbol
)
||
record
.
is_a?
(
String
)
route
<<
"
#{
record
}
_"
else
route
<<
"
#{
RecordIdentifier
.
__send__
(
"
#{
inflection
}
_class_name"
,
record
)
}
_"
route
<<
"
#{
RecordIdentifier
.
__send__
(
"plural_class_name"
,
record
)
}
"
route
=
route
.
singularize
if
inflection
==
:singular
route
<<
"_"
end
action_prefix
(
options
)
+
namespace
+
route
+
routing_type
(
options
).
to_s
...
...
actionpack/test/controller/polymorphic_routes_test.rb
浏览文件 @
d771e7d1
...
...
@@ -18,6 +18,20 @@ class Tag < Article
def
response_id
;
1
end
end
class
Tax
attr_reader
:id
def
save
;
@id
=
1
end
def
new_record?
;
@id
.
nil?
end
def
name
model
=
self
.
class
.
name
.
downcase
@id
.
nil?
?
"new
#{
model
}
"
:
"
#{
model
}
#
#{
@id
}
"
end
end
class
Fax
<
Tax
def
store_id
;
1
end
end
# TODO: test nested models
class
Response::Nested
<
Response
;
end
...
...
@@ -27,6 +41,8 @@ class PolymorphicRoutesTest < ActiveSupport::TestCase
def
setup
@article
=
Article
.
new
@response
=
Response
.
new
@tax
=
Tax
.
new
@fax
=
Fax
.
new
end
def
test_with_record
...
...
@@ -205,4 +221,73 @@ def test_polymorphic_path_does_not_modify_arguments
polymorphic_url
(
path
)
end
end
# Tests for names where .plural.singular doesn't round-trip
def
test_with_irregular_plural_record
@tax
.
save
expects
(
:taxis_url
).
with
(
@tax
)
polymorphic_url
(
@tax
)
end
def
test_with_irregular_plural_new_record
expects
(
:taxes_url
).
with
()
@tax
.
expects
(
:new_record?
).
returns
(
true
)
polymorphic_url
(
@tax
)
end
def
test_with_irregular_plural_record_and_action
expects
(
:new_taxis_url
).
with
()
@tax
.
expects
(
:new_record?
).
never
polymorphic_url
(
@tax
,
:action
=>
'new'
)
end
def
test_irregular_plural_url_helper_prefixed_with_new
expects
(
:new_taxis_url
).
with
()
new_polymorphic_url
(
@tax
)
end
def
test_irregular_plural_url_helper_prefixed_with_edit
@tax
.
save
expects
(
:edit_taxis_url
).
with
(
@tax
)
edit_polymorphic_url
(
@tax
)
end
def
test_with_nested_irregular_plurals
@fax
.
save
expects
(
:taxis_faxis_url
).
with
(
@tax
,
@fax
)
polymorphic_url
([
@tax
,
@fax
])
end
def
test_with_nested_unsaved_irregular_plurals
expects
(
:taxis_faxes_url
).
with
(
@tax
)
polymorphic_url
([
@tax
,
@fax
])
end
def
test_new_with_irregular_plural_array_and_namespace
expects
(
:new_admin_taxis_url
).
with
()
polymorphic_url
([
:admin
,
@tax
],
:action
=>
'new'
)
end
def
test_unsaved_with_irregular_plural_array_and_namespace
expects
(
:admin_taxes_url
).
with
()
polymorphic_url
([
:admin
,
@tax
])
end
def
test_nesting_with_irregular_plurals_and_array_ending_in_singleton_resource
expects
(
:taxis_faxis_url
).
with
(
@tax
)
polymorphic_url
([
@tax
,
:faxis
])
end
def
test_with_array_containing_single_irregular_plural_object
@tax
.
save
expects
(
:taxis_url
).
with
(
@tax
)
polymorphic_url
([
nil
,
@tax
])
end
def
test_with_array_containing_single_name_irregular_plural
@tax
.
save
expects
(
:taxes_url
)
polymorphic_url
([
:taxes
])
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录