Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
54cb0161
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,发现更多精彩内容 >>
未验证
提交
54cb0161
编写于
3月 14, 2020
作者:
K
Kasper Timm Hansen
提交者:
GitHub
3月 14, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #38495 from jonathanhefner/isolate-argv-in-command-invoke
Isolate ARGV in Rails::Command.invoke
上级
c82a9193
8ec7a2b7
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
44 addition
and
16 deletion
+44
-16
railties/lib/rails/command.rb
railties/lib/rails/command.rb
+7
-0
railties/lib/rails/commands/db/system/change/change_command.rb
...ies/lib/rails/commands/db/system/change/change_command.rb
+6
-1
railties/lib/rails/commands/test/test_command.rb
railties/lib/rails/commands/test/test_command.rb
+2
-2
railties/lib/rails/generators.rb
railties/lib/rails/generators.rb
+2
-3
railties/test/application/generators_test.rb
railties/test/application/generators_test.rb
+9
-10
railties/test/command/base_test.rb
railties/test/command/base_test.rb
+18
-0
未找到文件。
railties/lib/rails/command.rb
浏览文件 @
54cb0161
...
...
@@ -40,12 +40,19 @@ def invoke(full_namespace, args = [], **config)
command_name
,
namespace
=
"help"
,
"help"
if
command_name
.
blank?
||
HELP_MAPPINGS
.
include?
(
command_name
)
command_name
,
namespace
=
"version"
,
"version"
if
%w( -v --version )
.
include?
(
command_name
)
# isolate ARGV to ensure that commands depend only on the args they are given
args
=
args
.
dup
# args might *be* ARGV so dup before clearing
old_argv
=
ARGV
.
dup
ARGV
.
clear
command
=
find_by_namespace
(
namespace
,
command_name
)
if
command
&&
command
.
all_commands
[
command_name
]
command
.
perform
(
command_name
,
args
,
config
)
else
find_by_namespace
(
"rake"
).
perform
(
full_namespace
,
args
,
config
)
end
ensure
ARGV
.
replace
(
old_argv
)
end
# Rails finds namespaces similar to Thor, it only adds one rule:
...
...
railties/lib/rails/commands/db/system/change/change_command.rb
浏览文件 @
54cb0161
...
...
@@ -10,8 +10,13 @@ module System
class
ChangeCommand
<
Base
# :nodoc:
class_option
:to
,
desc:
"The database system to switch to."
def
initialize
(
positional_args
,
option_args
,
*
)
@argv
=
positional_args
+
option_args
super
end
def
perform
Rails
::
Generators
::
Db
::
System
::
ChangeGenerator
.
start
Rails
::
Generators
::
Db
::
System
::
ChangeGenerator
.
start
(
@argv
)
end
end
end
...
...
railties/lib/rails/commands/test/test_command.rb
浏览文件 @
54cb0161
...
...
@@ -29,8 +29,8 @@ def help
def
perform
(
*
)
$LOAD_PATH
<<
Rails
::
Command
.
root
.
join
(
"test"
).
to_s
Rails
::
TestUnit
::
Runner
.
parse_options
(
ARGV
)
Rails
::
TestUnit
::
Runner
.
run
(
ARGV
)
Rails
::
TestUnit
::
Runner
.
parse_options
(
args
)
Rails
::
TestUnit
::
Runner
.
run
(
args
)
end
end
end
...
...
railties/lib/rails/generators.rb
浏览文件 @
54cb0161
...
...
@@ -124,9 +124,8 @@ def api_only!
template_engine:
nil
)
if
ARGV
.
first
==
"mailer"
options
[
:rails
][
:template_engine
]
=
:erb
end
options
[
:mailer
]
||=
{}
options
[
:mailer
][
:template_engine
]
||=
:erb
end
# Returns an array of generator namespaces that are hidden.
...
...
railties/test/application/generators_test.rb
浏览文件 @
54cb0161
...
...
@@ -172,20 +172,19 @@ def with_bare_config
assert
File
.
exist?
(
File
.
join
(
rails_root
,
"app/views/notifier_mailer/foo.html.erb"
))
end
test
"ARGV is
mutated as expec
ted"
do
test
"ARGV is
popula
ted"
do
require
"
#{
app_path
}
/config/environment"
require
"rails/command"
Rails
::
Command
.
const_set
(
"APP_PATH"
,
"rails/all"
)
FileUtils
.
cd
(
rails_root
)
do
ARGV
=
[
"mailer"
,
"notifier"
,
"foo"
]
Rails
::
Command
.
const_set
(
"ARGV"
,
ARGV
)
quietly
{
Rails
::
Command
.
invoke
:generate
,
ARGV
}
Rails
.
application
.
load_generators
assert_equal
[
"notifier"
,
"foo"
],
ARGV
class
Rails::Generators::CheckArgvGenerator
<
Rails
::
Generators
::
Base
def
check_expected
raise
"ARGV.first is not expected"
unless
ARGV
.
first
==
"expected"
end
end
Rails
::
Command
.
send
(
:remove_const
,
"APP_PATH"
)
quietly
do
Rails
::
Command
.
invoke
(
:generate
,
[
"check_argv"
,
"expected"
])
# should not raise
end
end
test
"help does not show hidden namespaces and hidden commands"
do
...
...
railties/test/command/base_test.rb
浏览文件 @
54cb0161
...
...
@@ -12,4 +12,22 @@ class Rails::Command::BaseTest < ActiveSupport::TestCase
assert_equal
%w(secrets:setup secrets:edit secrets:show)
,
Rails
::
Command
::
SecretsCommand
.
printing_commands
assert_equal
%w(db:system:change)
,
Rails
::
Command
::
Db
::
System
::
ChangeCommand
.
printing_commands
end
test
"ARGV is isolated"
do
class
Rails::Command::ArgvCommand
<
Rails
::
Command
::
Base
def
check_isolation
raise
"not isolated"
unless
ARGV
.
empty?
ARGV
<<
"isolate this"
end
end
old_argv
=
ARGV
.
dup
new_argv
=
[
"foo"
,
"bar"
]
ARGV
.
replace
(
new_argv
)
Rails
::
Command
.
invoke
(
"argv:check_isolation"
)
# should not raise
assert_equal
new_argv
,
ARGV
ensure
ARGV
.
replace
(
old_argv
)
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录