Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
a288b74f
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,发现更多精彩内容 >>
提交
a288b74f
编写于
10月 28, 2009
作者:
J
José Valim
提交者:
Yehuda Katz
10月 28, 2009
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Generators should use Rails.root instead of Dir.pwd [#3408 status:resolved]
Signed-off-by:
N
Yehuda Katz
<
wycats@gmail.com
>
上级
8dcf91ca
变更
20
隐藏空白更改
内联
并排
Showing
20 changed file
with
44 addition
and
23 deletion
+44
-23
railties/lib/rails/generators/base.rb
railties/lib/rails/generators/base.rb
+17
-0
railties/test/generators/actions_test.rb
railties/test/generators/actions_test.rb
+1
-1
railties/test/generators/app_generator_test.rb
railties/test/generators/app_generator_test.rb
+2
-2
railties/test/generators/controller_generator_test.rb
railties/test/generators/controller_generator_test.rb
+1
-1
railties/test/generators/generator_generator_test.rb
railties/test/generators/generator_generator_test.rb
+1
-1
railties/test/generators/generators_test_helper.rb
railties/test/generators/generators_test_helper.rb
+8
-3
railties/test/generators/helper_generator_test.rb
railties/test/generators/helper_generator_test.rb
+1
-1
railties/test/generators/integration_test_generator_test.rb
railties/test/generators/integration_test_generator_test.rb
+1
-1
railties/test/generators/mailer_generator_test.rb
railties/test/generators/mailer_generator_test.rb
+1
-1
railties/test/generators/metal_generator_test.rb
railties/test/generators/metal_generator_test.rb
+1
-1
railties/test/generators/migration_generator_test.rb
railties/test/generators/migration_generator_test.rb
+1
-1
railties/test/generators/model_generator_test.rb
railties/test/generators/model_generator_test.rb
+1
-1
railties/test/generators/observer_generator_test.rb
railties/test/generators/observer_generator_test.rb
+1
-1
railties/test/generators/performance_test_generator_test.rb
railties/test/generators/performance_test_generator_test.rb
+1
-1
railties/test/generators/plugin_generator_test.rb
railties/test/generators/plugin_generator_test.rb
+1
-1
railties/test/generators/resource_generator_test.rb
railties/test/generators/resource_generator_test.rb
+1
-1
railties/test/generators/scaffold_controller_generator_test.rb
...ies/test/generators/scaffold_controller_generator_test.rb
+1
-1
railties/test/generators/scaffold_generator_test.rb
railties/test/generators/scaffold_generator_test.rb
+1
-2
railties/test/generators/session_migration_generator_test.rb
railties/test/generators/session_migration_generator_test.rb
+1
-1
railties/test/generators/stylesheets_generator_test.rb
railties/test/generators/stylesheets_generator_test.rb
+1
-1
未找到文件。
railties/lib/rails/generators/base.rb
浏览文件 @
a288b74f
...
@@ -12,6 +12,16 @@ class Base < Thor::Group
...
@@ -12,6 +12,16 @@ class Base < Thor::Group
add_runtime_options!
add_runtime_options!
# Always move to rails source root.
#
def
initialize
(
*
args
)
#:nodoc:
if
!
invoked?
(
args
)
&&
defined?
(
Rails
.
root
)
&&
Rails
.
root
self
.
destination_root
=
Rails
.
root
FileUtils
.
cd
(
destination_root
)
end
super
end
# Automatically sets the source root based on the class name.
# Automatically sets the source root based on the class name.
#
#
def
self
.
source_root
def
self
.
source_root
...
@@ -247,6 +257,13 @@ def class_collisions(*class_names) #:nodoc:
...
@@ -247,6 +257,13 @@ def class_collisions(*class_names) #:nodoc:
end
end
end
end
# Check if this generator was invoked from another one by inspecting
# parameters.
#
def
invoked?
(
args
)
args
.
last
.
is_a?
(
Hash
)
&&
args
.
last
.
key?
(
:invocations
)
end
# Use Rails default banner.
# Use Rails default banner.
#
#
def
self
.
banner
def
self
.
banner
...
...
railties/test/generators/actions_test.rb
浏览文件 @
a288b74f
...
@@ -182,7 +182,7 @@ def run_generator
...
@@ -182,7 +182,7 @@ def run_generator
end
end
def
generator
(
config
=
{})
def
generator
(
config
=
{})
@generator
||=
Rails
::
Generators
::
Base
.
new
([],
{},
{
:destination_root
=>
destination_root
}.
merge!
(
config
)
)
@generator
||=
Rails
::
Generators
::
Base
.
new
([],
{},
config
)
end
end
def
action
(
*
args
,
&
block
)
def
action
(
*
args
,
&
block
)
...
...
railties/test/generators/app_generator_test.rb
浏览文件 @
a288b74f
...
@@ -126,7 +126,7 @@ def test_rails_is_frozen
...
@@ -126,7 +126,7 @@ def test_rails_is_frozen
def
test_template_from_dir_pwd
def
test_template_from_dir_pwd
FileUtils
.
cd
(
Rails
.
root
)
FileUtils
.
cd
(
Rails
.
root
)
assert_match
/It works from file!/
,
run_generator
([
"-m"
,
"lib/template.rb"
])
assert_match
/It works from file!/
,
run_generator
([
"-m"
,
"
../
lib/template.rb"
])
end
end
def
test_template_raises_an_error_with_invalid_path
def
test_template_raises_an_error_with_invalid_path
...
@@ -170,7 +170,7 @@ def run_generator(args=[])
...
@@ -170,7 +170,7 @@ def run_generator(args=[])
end
end
def
generator
(
options
=
{})
def
generator
(
options
=
{})
@generator
||=
Rails
::
Generators
::
AppGenerator
.
new
([
destination_root
],
options
,
:destination_root
=>
destination_root
)
@generator
||=
Rails
::
Generators
::
AppGenerator
.
new
([
destination_root
],
options
)
end
end
def
action
(
*
args
,
&
block
)
def
action
(
*
args
,
&
block
)
...
...
railties/test/generators/controller_generator_test.rb
浏览文件 @
a288b74f
...
@@ -74,7 +74,7 @@ def test_actions_are_turned_into_methods
...
@@ -74,7 +74,7 @@ def test_actions_are_turned_into_methods
protected
protected
def
run_generator
(
args
=
[
"Account"
,
"foo"
,
"bar"
])
def
run_generator
(
args
=
[
"Account"
,
"foo"
,
"bar"
])
silence
(
:stdout
)
{
Rails
::
Generators
::
ControllerGenerator
.
start
args
,
:destination_root
=>
destination_root
}
silence
(
:stdout
)
{
Rails
::
Generators
::
ControllerGenerator
.
start
args
}
end
end
end
end
railties/test/generators/generator_generator_test.rb
浏览文件 @
a288b74f
...
@@ -20,7 +20,7 @@ def test_generator_skeleton_is_created
...
@@ -20,7 +20,7 @@ def test_generator_skeleton_is_created
protected
protected
def
run_generator
(
args
=
[
"awesome"
],
config
=
{})
def
run_generator
(
args
=
[
"awesome"
],
config
=
{})
silence
(
:stdout
)
{
Rails
::
Generators
::
GeneratorGenerator
.
start
args
,
config
.
merge
(
:destination_root
=>
destination_root
)
}
silence
(
:stdout
)
{
Rails
::
Generators
::
GeneratorGenerator
.
start
args
,
config
}
end
end
end
end
railties/test/generators/generators_test_helper.rb
浏览文件 @
a288b74f
# TODO: Fix this RAILS_ENV stuff
# TODO: Fix this RAILS_ENV stuff
RAILS_ENV
=
'test'
RAILS_ENV
=
'test'
unless
defined?
(
RAILS_ENV
)
require
'abstract_unit'
require
'abstract_unit'
Rails
.
application
.
config
.
root
=
File
.
expand_path
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'..'
,
'fixtures'
))
Rails
.
application
.
config
.
root
=
File
.
expand_path
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'..'
,
'fixtures'
))
...
@@ -11,12 +11,17 @@
...
@@ -11,12 +11,17 @@
CURRENT_PATH
=
File
.
expand_path
(
Dir
.
pwd
)
CURRENT_PATH
=
File
.
expand_path
(
Dir
.
pwd
)
Rails
::
Generators
.
no_color!
Rails
::
Generators
.
no_color!
module
Rails
def
self
.
root
@root
||=
File
.
expand_path
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'..'
,
'fixtures'
,
'tmp'
))
end
end
class
GeneratorsTestCase
<
Test
::
Unit
::
TestCase
class
GeneratorsTestCase
<
Test
::
Unit
::
TestCase
include
FileUtils
include
FileUtils
def
destination_root
def
destination_root
@destination_root
||=
File
.
expand_path
(
File
.
join
(
File
.
dirname
(
__FILE__
),
Rails
.
root
'..'
,
'fixtures'
,
'tmp'
))
end
end
def
setup
def
setup
...
...
railties/test/generators/helper_generator_test.rb
浏览文件 @
a288b74f
...
@@ -54,7 +54,7 @@ def test_namespaced_and_not_namespaced_helpers
...
@@ -54,7 +54,7 @@ def test_namespaced_and_not_namespaced_helpers
protected
protected
def
run_generator
(
args
=
[
"admin"
])
def
run_generator
(
args
=
[
"admin"
])
silence
(
:stdout
)
{
Rails
::
Generators
::
HelperGenerator
.
start
args
,
:destination_root
=>
destination_root
}
silence
(
:stdout
)
{
Rails
::
Generators
::
HelperGenerator
.
start
args
}
end
end
end
end
railties/test/generators/integration_test_generator_test.rb
浏览文件 @
a288b74f
...
@@ -12,7 +12,7 @@ def test_integration_test_skeleton_is_created
...
@@ -12,7 +12,7 @@ def test_integration_test_skeleton_is_created
protected
protected
def
run_generator
(
args
=
[
"integration"
])
def
run_generator
(
args
=
[
"integration"
])
silence
(
:stdout
)
{
Rails
::
Generators
::
IntegrationTestGenerator
.
start
args
,
:destination_root
=>
destination_root
}
silence
(
:stdout
)
{
Rails
::
Generators
::
IntegrationTestGenerator
.
start
args
}
end
end
end
end
railties/test/generators/mailer_generator_test.rb
浏览文件 @
a288b74f
...
@@ -46,7 +46,7 @@ def test_actions_are_turned_into_methods
...
@@ -46,7 +46,7 @@ def test_actions_are_turned_into_methods
protected
protected
def
run_generator
(
args
=
[
"notifier"
,
"foo"
,
"bar"
])
def
run_generator
(
args
=
[
"notifier"
,
"foo"
,
"bar"
])
silence
(
:stdout
)
{
Rails
::
Generators
::
MailerGenerator
.
start
args
,
:destination_root
=>
destination_root
}
silence
(
:stdout
)
{
Rails
::
Generators
::
MailerGenerator
.
start
args
}
end
end
end
end
railties/test/generators/metal_generator_test.rb
浏览文件 @
a288b74f
...
@@ -17,7 +17,7 @@ def test_check_class_collision
...
@@ -17,7 +17,7 @@ def test_check_class_collision
protected
protected
def
run_generator
(
args
=
[
"foo"
])
def
run_generator
(
args
=
[
"foo"
])
silence
(
:stdout
)
{
Rails
::
Generators
::
MetalGenerator
.
start
args
,
:destination_root
=>
destination_root
}
silence
(
:stdout
)
{
Rails
::
Generators
::
MetalGenerator
.
start
args
}
end
end
end
end
railties/test/generators/migration_generator_test.rb
浏览文件 @
a288b74f
...
@@ -53,7 +53,7 @@ def test_remove_migration_with_attributes
...
@@ -53,7 +53,7 @@ def test_remove_migration_with_attributes
protected
protected
def
run_generator
(
args
=
[
@migration
])
def
run_generator
(
args
=
[
@migration
])
silence
(
:stdout
)
{
Rails
::
Generators
::
MigrationGenerator
.
start
args
,
:destination_root
=>
destination_root
}
silence
(
:stdout
)
{
Rails
::
Generators
::
MigrationGenerator
.
start
args
}
end
end
end
end
railties/test/generators/model_generator_test.rb
浏览文件 @
a288b74f
...
@@ -175,7 +175,7 @@ def test_check_class_collision
...
@@ -175,7 +175,7 @@ def test_check_class_collision
protected
protected
def
run_generator
(
args
=
[
"Account"
,
"name:string"
,
"age:integer"
],
config
=
{})
def
run_generator
(
args
=
[
"Account"
,
"name:string"
,
"age:integer"
],
config
=
{})
silence
(
:stdout
)
{
Rails
::
Generators
::
ModelGenerator
.
start
args
,
config
.
merge
(
:destination_root
=>
destination_root
)
}
silence
(
:stdout
)
{
Rails
::
Generators
::
ModelGenerator
.
start
args
,
config
}
end
end
end
end
railties/test/generators/observer_generator_test.rb
浏览文件 @
a288b74f
...
@@ -27,7 +27,7 @@ def test_logs_if_the_test_framework_cannot_be_found
...
@@ -27,7 +27,7 @@ def test_logs_if_the_test_framework_cannot_be_found
protected
protected
def
run_generator
(
args
=
[
"account"
])
def
run_generator
(
args
=
[
"account"
])
silence
(
:stdout
)
{
Rails
::
Generators
::
ObserverGenerator
.
start
args
,
:destination_root
=>
destination_root
}
silence
(
:stdout
)
{
Rails
::
Generators
::
ObserverGenerator
.
start
args
}
end
end
end
end
railties/test/generators/performance_test_generator_test.rb
浏览文件 @
a288b74f
...
@@ -12,7 +12,7 @@ def test_performance_test_skeleton_is_created
...
@@ -12,7 +12,7 @@ def test_performance_test_skeleton_is_created
protected
protected
def
run_generator
(
args
=
[
"performance"
])
def
run_generator
(
args
=
[
"performance"
])
silence
(
:stdout
)
{
Rails
::
Generators
::
PerformanceTestGenerator
.
start
args
,
:destination_root
=>
destination_root
}
silence
(
:stdout
)
{
Rails
::
Generators
::
PerformanceTestGenerator
.
start
args
}
end
end
end
end
railties/test/generators/plugin_generator_test.rb
浏览文件 @
a288b74f
...
@@ -50,7 +50,7 @@ def test_plugin_generator_on_revoke
...
@@ -50,7 +50,7 @@ def test_plugin_generator_on_revoke
protected
protected
def
run_generator
(
args
=
[
"plugin_fu"
],
config
=
{})
def
run_generator
(
args
=
[
"plugin_fu"
],
config
=
{})
silence
(
:stdout
)
{
Rails
::
Generators
::
PluginGenerator
.
start
args
,
config
.
merge
(
:destination_root
=>
destination_root
)
}
silence
(
:stdout
){
Rails
::
Generators
::
PluginGenerator
.
start
args
,
config
}
end
end
end
end
railties/test/generators/resource_generator_test.rb
浏览文件 @
a288b74f
...
@@ -100,7 +100,7 @@ def test_route_is_removed_on_revoke
...
@@ -100,7 +100,7 @@ def test_route_is_removed_on_revoke
protected
protected
def
run_generator
(
args
=
[
"account"
],
config
=
{})
def
run_generator
(
args
=
[
"account"
],
config
=
{})
silence
(
:stdout
)
{
Rails
::
Generators
::
ResourceGenerator
.
start
args
,
config
.
merge
(
:destination_root
=>
destination_root
)
}
silence
(
:stdout
)
{
Rails
::
Generators
::
ResourceGenerator
.
start
args
,
config
}
end
end
end
end
railties/test/generators/scaffold_controller_generator_test.rb
浏览文件 @
a288b74f
...
@@ -139,7 +139,7 @@ def self.all(klass)
...
@@ -139,7 +139,7 @@ def self.all(klass)
protected
protected
def
run_generator
(
args
=
[
"User"
,
"name:string"
,
"age:integer"
])
def
run_generator
(
args
=
[
"User"
,
"name:string"
,
"age:integer"
])
silence
(
:stdout
)
{
Rails
::
Generators
::
ScaffoldControllerGenerator
.
start
args
,
:destination_root
=>
destination_root
}
silence
(
:stdout
)
{
Rails
::
Generators
::
ScaffoldControllerGenerator
.
start
args
}
end
end
end
end
railties/test/generators/scaffold_generator_test.rb
浏览文件 @
a288b74f
...
@@ -122,8 +122,7 @@ def test_scaffold_on_revoke
...
@@ -122,8 +122,7 @@ def test_scaffold_on_revoke
def
run_generator
(
config
=
{})
def
run_generator
(
config
=
{})
silence
(
:stdout
)
do
silence
(
:stdout
)
do
Rails
::
Generators
::
ScaffoldGenerator
.
start
[
"product_line"
,
"title:string"
,
"price:integer"
],
Rails
::
Generators
::
ScaffoldGenerator
.
start
[
"product_line"
,
"title:string"
,
"price:integer"
],
config
config
.
merge
(
:destination_root
=>
destination_root
)
end
end
end
end
...
...
railties/test/generators/session_migration_generator_test.rb
浏览文件 @
a288b74f
...
@@ -28,7 +28,7 @@ def test_session_migration_with_custom_table_name
...
@@ -28,7 +28,7 @@ def test_session_migration_with_custom_table_name
protected
protected
def
run_generator
(
args
=
[])
def
run_generator
(
args
=
[])
silence
(
:stdout
)
{
Rails
::
Generators
::
SessionMigrationGenerator
.
start
args
,
:destination_root
=>
destination_root
}
silence
(
:stdout
)
{
Rails
::
Generators
::
SessionMigrationGenerator
.
start
args
}
end
end
end
end
railties/test/generators/stylesheets_generator_test.rb
浏览文件 @
a288b74f
...
@@ -18,7 +18,7 @@ def test_stylesheets_are_not_deleted_on_revoke
...
@@ -18,7 +18,7 @@ def test_stylesheets_are_not_deleted_on_revoke
protected
protected
def
run_generator
(
config
=
{})
def
run_generator
(
config
=
{})
silence
(
:stdout
)
{
Rails
::
Generators
::
StylesheetsGenerator
.
start
[],
config
.
merge
(
:destination_root
=>
destination_root
)
}
silence
(
:stdout
)
{
Rails
::
Generators
::
StylesheetsGenerator
.
start
[],
config
}
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录