Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
85de1830
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,体验更适合开发者的 AI 搜索 >>
提交
85de1830
编写于
4月 11, 2013
作者:
X
Xavier Noria
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
application loader refactor and test suite complete rewrite
上级
2a07db71
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
71 addition
and
58 deletion
+71
-58
railties/lib/rails/app_rails_loader.rb
railties/lib/rails/app_rails_loader.rb
+27
-28
railties/test/app_rails_loader_test.rb
railties/test/app_rails_loader_test.rb
+44
-30
未找到文件。
railties/lib/rails/app_rails_loader.rb
浏览文件 @
85de1830
...
...
@@ -4,28 +4,7 @@ module Rails
module
AppRailsLoader
RUBY
=
File
.
join
(
*
RbConfig
::
CONFIG
.
values_at
(
"bindir"
,
"ruby_install_name"
))
+
RbConfig
::
CONFIG
[
"EXEEXT"
]
EXECUTABLES
=
[
'bin/rails'
,
'script/rails'
]
def
self
.
exec_app_rails
original_cwd
=
Dir
.
pwd
until
exe
=
find_executable
# If we exhaust the search there is no executable, this could be a
# call to generate a new application, so restore the original cwd.
Dir
.
chdir
(
original_cwd
)
and
return
if
Pathname
.
new
(
Dir
.
pwd
).
root?
# Otherwise keep moving upwards in search of a executable.
Dir
.
chdir
(
'..'
)
end
contents
=
File
.
read
(
exe
)
# This is the Rails executable, let's use it
if
contents
=~
/(APP|ENGINE)_PATH/
exec
RUBY
,
exe
,
*
ARGV
# This is a Bundler binstub. Stop and explain how to upgrade.
elsif
exe
=~
/bin\/rails$/
&&
contents
=~
/This file was generated by Bundler/
$stderr
.
puts
<<-
end_bin_upgrade_warning
BUNDLER_WARNING
=
<<
EOS
Looks like your app's ./bin/rails is a stub that was generated by Bundler.
In Rails 4, your app's bin/ directory contains executables that are versioned
...
...
@@ -45,14 +24,34 @@ def self.exec_app_rails
bundle binstubs some-gem-name
git add bin/new-executable
end_bin_upgrade_warning
EOS
def
self
.
exec_app_rails
original_cwd
=
Dir
.
pwd
loop
do
if
exe
=
find_executable
contents
=
File
.
read
(
exe
)
if
contents
=~
/(APP|ENGINE)_PATH/
exec
RUBY
,
exe
,
*
ARGV
break
# non reachable, hack to be able to stub exec in the test suite
elsif
exe
.
end_with?
(
'bin/rails'
)
&&
contents
.
include?
(
'This file was generated by Bundler'
)
$stderr
.
puts
(
BUNDLER_WARNING
)
Object
.
const_set
(
:APP_PATH
,
File
.
expand_path
(
'config/application'
,
Dir
.
pwd
))
require
File
.
expand_path
(
'../boot'
,
APP_PATH
)
require
'rails/commands'
break
end
end
Object
.
const_set
(
:APP_PATH
,
File
.
expand_path
(
'config/application'
,
Dir
.
pwd
))
require
File
.
expand_path
(
'../boot'
,
APP_PATH
)
require
'rails/commands'
# If we exhaust the search there is no executable, this could be a
# call to generate a new application, so restore the original cwd.
Dir
.
chdir
(
original_cwd
)
and
return
if
Pathname
.
new
(
Dir
.
pwd
).
root?
# Otherwise keep moving upwards in search of a executable.
Dir
.
chdir
(
'..'
)
end
rescue
SystemCallError
# could not chdir, no problem just return
end
def
self
.
find_executable
...
...
railties/test/app_rails_loader_test.rb
浏览文件 @
85de1830
require
'pathname'
require
'abstract_unit'
require
'rails/app_rails_loader'
class
AppRailsLoaderTest
<
ActiveSupport
::
TestCase
def
write
(
filename
,
contents
=
nil
)
FileUtils
.
mkdir_p
(
Pathname
.
new
(
filename
).
dirname
)
File
.
write
(
filename
,
contents
)
end
def
expects_exec
(
exe
)
Rails
::
AppRailsLoader
.
expects
(
:exec
).
with
(
Rails
::
AppRailsLoader
::
RUBY
,
exe
)
end
setup
do
File
.
stubs
(
:exists?
).
returns
(
false
)
@tmp
=
Dir
.
mktmpdir
(
'railties-rails-loader-test-suite'
)
@cwd
=
Dir
.
pwd
Dir
.
chdir
(
@tmp
)
end
[
'bin
/rails'
,
'script/rails'
].
each
do
|
exe
|
test
"is in a rails application if
#{
exe
}
exists and contains APP_PATH"
do
File
.
stubs
(
:exists?
).
with
(
exe
).
returns
(
true
)
File
.
stubs
(
:read
).
with
(
exe
).
returns
(
'APP_PATH'
)
assert
Rails
::
AppRailsLoader
.
find_executable
end
[
'bin
'
,
'script'
].
each
do
|
script_dir
|
exe
=
"
#{
script_dir
}
/rails"
test
"is not in a Rails application if
#{
exe
}
is not found in the current or parent directories"
do
File
.
stubs
(
:exists?
).
with
(
'bin/rails'
).
returns
(
false
)
File
.
stubs
(
:exists?
).
with
(
'script/rails'
).
returns
(
false
)
test
"is not in a rails application if
#{
exe
}
exists but doesn't contain APP_PATH"
do
File
.
stubs
(
:exists?
).
with
(
exe
).
returns
(
true
)
File
.
stubs
(
:read
).
with
(
exe
).
returns
(
"railties
#{
exe
}
"
)
assert
!
Rails
::
AppRailsLoader
.
exec_app_rails
end
test
"is in a rails application if parent directory has
#{
exe
}
containing APP_PATH"
do
File
.
stubs
(
:exists?
).
with
(
"/foo/bar/
#{
exe
}
"
).
returns
(
false
)
File
.
stubs
(
:exists?
).
with
(
"/foo/
#{
exe
}
"
).
returns
(
true
)
File
.
stubs
(
:read
).
with
(
"/foo/
#{
exe
}
"
).
returns
(
'APP_PATH'
)
assert_equal
Rails
::
AppRailsLoader
.
find_executable_in_parent_path
(
Pathname
.
new
(
"/foo/bar"
)),
"/foo/
#{
exe
}
"
end
[
'APP_PATH'
,
'ENGINE_PATH'
].
each
do
|
keyword
|
test
"is in a Rails application if
#{
exe
}
exists and contains
#{
keyword
}
"
do
write
exe
,
keyword
test
"is not in a rails application if at the root directory and doesn't have
#{
exe
}
"
do
Pathname
.
any_instance
.
stubs
(
:root?
).
returns
true
assert
!
Rails
::
AppRailsLoader
.
find_executable
end
expects_exec
exe
Rails
::
AppRailsLoader
.
exec_app_rails
end
test
"is in a rails engine if parent directory has
#{
exe
}
containing ENGINE_PATH"
do
File
.
stubs
(
:exists?
).
with
(
"/foo/bar/
#{
exe
}
"
).
returns
(
false
)
File
.
stubs
(
:exists?
).
with
(
"/foo/
#{
exe
}
"
).
returns
(
true
)
File
.
stubs
(
:read
).
with
(
"/foo/
#{
exe
}
"
).
returns
(
'ENGINE_PATH'
)
assert
Rails
::
AppRailsLoader
.
find_executable_in_parent_path
(
Pathname
.
new
(
"/foo/bar"
)),
"/foo/
#{
exe
}
"
end
test
"is not in a Rails application if
#{
exe
}
exists but doesn't contain
#{
keyword
}
"
do
write
exe
assert
!
Rails
::
AppRailsLoader
.
exec_app_rails
end
test
"is in a rails application if parent directory has
#{
exe
}
containing
#{
keyword
}
and chdirs to the root directory"
do
write
"foo/bar/
#{
exe
}
"
write
"foo/
#{
exe
}
"
,
keyword
test
"is in a rails engine if
#{
exe
}
exists containing ENGINE_PATH"
do
File
.
stubs
(
:exists?
).
with
(
exe
).
returns
(
true
)
File
.
stubs
(
:read
).
with
(
exe
).
returns
(
'ENGINE_PATH'
)
assert
Rails
::
AppRailsLoader
.
find_executable
Dir
.
chdir
(
'foo/bar'
)
expects_exec
exe
Rails
::
AppRailsLoader
.
exec_app_rails
assert_equal
File
.
join
(
@tmp
,
'foo'
),
Dir
.
pwd
end
end
end
teardown
do
Dir
.
chdir
(
@cwd
)
FileUtils
.
rm_rf
(
@tmp
)
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录