Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
a3117335
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,发现更多精彩内容 >>
提交
a3117335
编写于
9月 29, 2012
作者:
J
Jeremy Walker
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed generated whitespace in routes when using namespaced resource.
上级
4fd0f905
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
115 addition
and
6 deletion
+115
-6
railties/lib/rails/generators/rails/resource_route/resource_route_generator.rb
...nerators/rails/resource_route/resource_route_generator.rb
+41
-4
railties/test/generators/namespaced_generators_test.rb
railties/test/generators/namespaced_generators_test.rb
+74
-2
未找到文件。
railties/lib/rails/generators/rails/resource_route/resource_route_generator.rb
浏览文件 @
a3117335
module
Rails
module
Generators
class
ResourceRouteGenerator
<
NamedBase
# Properly nests namespaces passed into a generator
#
# $ rails generate resource admin/users/products
#
# should give you
#
# namespace :admin do
# namespace :users
# resources :products
# end
# end
def
add_resource_route
return
if
options
[
:actions
].
present?
route_config
=
regular_class_path
.
collect
{
|
namespace
|
"namespace :
#{
namespace
}
do "
}.
join
(
" "
)
route_config
<<
"resources :
#{
file_name
.
pluralize
}
"
route_config
<<
" end"
*
regular_class_path
.
size
route
route_config
# iterates over all namespaces and opens up blocks
regular_class_path
.
each_with_index
do
|
namespace
,
index
|
write
(
"namespace :
#{
namespace
}
do"
,
index
+
1
)
end
# inserts the primary resource
write
(
"resources :
#{
file_name
.
pluralize
}
"
,
route_length
+
1
)
# ends blocks
regular_class_path
.
each_index
do
|
index
|
write
(
"end"
,
route_length
-
index
)
end
# route prepends two spaces onto the front of the string that is passed, this corrects that
route
route_string
[
2
..-
1
]
end
private
def
route_string
@route_string
||=
""
end
def
write
(
str
,
indent
)
route_string
<<
"
#{
" "
*
indent
}#{
str
}
\n
"
end
def
route_length
regular_class_path
.
length
end
end
end
end
railties/test/generators/namespaced_generators_test.rb
浏览文件 @
a3117335
...
...
@@ -304,7 +304,7 @@ def test_scaffold_with_namespace_on_invoke
# Route
assert_file
"config/routes.rb"
do
|
route
|
assert_match
(
/
namespace :admin do resources :roles
end$/
,
route
)
assert_match
(
/
^ namespace :admin do\n resources :roles\n
end$/
,
route
)
end
# Controller
...
...
@@ -346,7 +346,7 @@ def test_scaffold_with_namespace_on_revoke
# Route
assert_file
"config/routes.rb"
do
|
route
|
assert_no_match
(
/
namespace :admin do resources :roles end
$/
,
route
)
assert_no_match
(
/
^ namespace :admin do\n resources :roles\n end$
$/
,
route
)
end
# Controller
...
...
@@ -364,4 +364,76 @@ def test_scaffold_with_namespace_on_revoke
# Stylesheets (should not be removed)
assert_file
"app/assets/stylesheets/scaffold.css"
end
def
test_scaffold_with_nested_namespace_on_invoke
run_generator
[
"admin/user/special/role"
,
"name:string"
,
"description:string"
]
# Model
assert_file
"app/models/test_app/admin/user/special.rb"
,
/module TestApp\n module Admin/
assert_file
"app/models/test_app/admin/user/special/role.rb"
,
/module TestApp\n class Admin::User::Special::Role < ActiveRecord::Base/
assert_file
"test/unit/test_app/admin/user/special/role_test.rb"
,
/module TestApp\n class Admin::User::Special::RoleTest < ActiveSupport::TestCase/
assert_file
"test/fixtures/test_app/admin/user/special/roles.yml"
assert_migration
"db/migrate/create_test_app_admin_user_special_roles.rb"
# Route
assert_file
"config/routes.rb"
do
|
route
|
assert_match
(
/^ namespace :admin do\n namespace :user do\n namespace :special do\n resources :roles\n end\n end\n end$/
,
route
)
end
# Controller
assert_file
"app/controllers/test_app/admin/user/special/roles_controller.rb"
do
|
content
|
assert_match
(
/module TestApp\n class Admin::User::Special::RolesController < ApplicationController/
,
content
)
end
assert_file
"test/functional/test_app/admin/user/special/roles_controller_test.rb"
,
/module TestApp\n class Admin::User::Special::RolesControllerTest < ActionController::TestCase/
# Views
%w(
index
edit
new
show
_form
)
.
each
{
|
view
|
assert_file
"app/views/test_app/admin/user/special/roles/
#{
view
}
.html.erb"
}
assert_no_file
"app/views/layouts/admin/user/special/roles.html.erb"
# Helpers
assert_file
"app/helpers/test_app/admin/user/special/roles_helper.rb"
assert_file
"test/unit/helpers/test_app/admin/user/special/roles_helper_test.rb"
# Stylesheets
assert_file
"app/assets/stylesheets/scaffold.css"
end
def
test_scaffold_with_nested_namespace_on_revoke
run_generator
[
"admin/user/special/role"
,
"name:string"
,
"description:string"
]
run_generator
[
"admin/user/special/role"
],
:behavior
=>
:revoke
# Model
assert_file
"app/models/test_app/admin/user/special.rb"
# ( should not be remove )
assert_no_file
"app/models/test_app/admin/user/special/role.rb"
assert_no_file
"test/unit/test_app/admin/user/special/role_test.rb"
assert_no_file
"test/fixtures/test_app/admin/user/special/roles.yml"
assert_no_migration
"db/migrate/create_test_app_admin_user_special_roles.rb"
# Route
assert_file
"config/routes.rb"
do
|
route
|
assert_no_match
(
/^ namespace :admin do\n namespace :user do\n namespace :special do\n resources :roles\n end\n end\n end$/
,
route
)
end
# Controller
assert_no_file
"app/controllers/test_app/admin/user/special/roles_controller.rb"
assert_no_file
"test/functional/test_app/admin/user/special/roles_controller_test.rb"
# Views
assert_no_file
"app/views/test_app/admin/user/special/roles"
# Helpers
assert_no_file
"app/helpers/test_app/admin/user/special/roles_helper.rb"
assert_no_file
"test/unit/helpers/test_app/admin/user/special/roles_helper_test.rb"
# Stylesheets (should not be removed)
assert_file
"app/assets/stylesheets/scaffold.css"
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录