Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
6b086449
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,发现更多精彩内容 >>
提交
6b086449
编写于
9月 29, 2009
作者:
C
Carl Lerche
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix the broken railties isolation tests
上级
6f6a589d
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
86 addition
and
121 deletion
+86
-121
activesupport/lib/active_support/testing/isolation.rb
activesupport/lib/active_support/testing/isolation.rb
+9
-4
railties/lib/rails/application.rb
railties/lib/rails/application.rb
+3
-3
railties/test/application/load_test.rb
railties/test/application/load_test.rb
+18
-3
railties/test/boot_test.rb
railties/test/boot_test.rb
+2
-2
railties/test/initializer/check_ruby_version_test.rb
railties/test/initializer/check_ruby_version_test.rb
+6
-1
railties/test/initializer/install_gem_spec_stubs_test.rb
railties/test/initializer/install_gem_spec_stubs_test.rb
+0
-86
railties/test/initializer/path_test.rb
railties/test/initializer/path_test.rb
+15
-17
railties/test/isolation/abstract_unit.rb
railties/test/isolation/abstract_unit.rb
+33
-5
未找到文件。
activesupport/lib/active_support/testing/isolation.rb
浏览文件 @
6b086449
...
@@ -31,10 +31,15 @@ def run(result)
...
@@ -31,10 +31,15 @@ def run(result)
@_result
=
result
@_result
=
result
proxy
=
run_in_isolation
do
|
proxy
|
serialized
=
run_in_isolation
do
|
proxy
|
begin
super
(
proxy
)
{
}
super
(
proxy
)
{
}
rescue
Exception
=>
e
proxy
.
add_error
(
Test
::
Unit
::
Error
.
new
(
name
,
e
))
end
end
end
proxy
=
Marshal
.
load
(
serialized
)
proxy
.
__replay__
(
@_result
)
proxy
.
__replay__
(
@_result
)
yield
(
Test
::
Unit
::
TestCase
::
FINISHED
,
name
)
yield
(
Test
::
Unit
::
TestCase
::
FINISHED
,
name
)
...
@@ -55,7 +60,7 @@ def run_in_isolation(&blk)
...
@@ -55,7 +60,7 @@ def run_in_isolation(&blk)
write
.
close
write
.
close
result
=
read
.
read
result
=
read
.
read
Process
.
wait2
(
pid
)
Process
.
wait2
(
pid
)
Marshal
.
load
(
result
.
unpack
(
"m"
)[
0
])
return
result
.
unpack
(
"m"
)[
0
]
end
end
end
end
...
@@ -83,7 +88,7 @@ def run_in_isolation(&blk)
...
@@ -83,7 +88,7 @@ def run_in_isolation(&blk)
ENV
.
delete
(
"ISOLATION_TEST"
)
ENV
.
delete
(
"ISOLATION_TEST"
)
ENV
.
delete
(
"ISOLATION_OUTPUT"
)
ENV
.
delete
(
"ISOLATION_OUTPUT"
)
return
Marshal
.
load
(
tmpfile
.
read
.
unpack
(
"m"
)[
0
])
return
tmpfile
.
read
.
unpack
(
"m"
)[
0
]
end
end
end
end
end
end
...
...
railties/lib/rails/application.rb
浏览文件 @
6b086449
module
Rails
module
Rails
class
Application
class
Application
attr_accessor
:
routes
,
:
config
attr_accessor
:config
def
self
.
load
(
environment_file
)
def
self
.
load
(
environment_file
)
environment
=
File
.
read
(
environment_file
)
environment
=
File
.
read
(
environment_file
)
Object
.
class_eval
(
environment
,
environment_file
)
Object
.
class_eval
(
environment
,
environment_file
)
end
end
def
initialize
def
routes
@routes
=
ActionController
::
Routing
::
Routes
ActionController
::
Routing
::
Routes
end
end
def
middleware
def
middleware
...
...
railties/test/application/load_test.rb
浏览文件 @
6b086449
require
"isolation/abstract_unit"
require
"isolation/abstract_unit"
require
"rails"
#
require "rails"
require
'action_dispatch'
#
require 'action_dispatch'
module
ApplicationTests
module
ApplicationTests
class
LoadTest
<
Test
::
Unit
::
TestCase
class
LoadTest
<
Test
::
Unit
::
TestCase
include
ActiveSupport
::
Testing
::
Isolation
include
ActiveSupport
::
Testing
::
Isolation
def
rackup
def
rackup
ActionDispatch
::
Utils
.
parse_config
(
"
#{
app_path
}
/config.ru"
)
config
=
"
#{
app_path
}
/config.ru"
# Copied from ActionDispatch::Utils.parse_config
# ActionDispatch is not necessarily available at this point.
require
'rack'
if
config
=~
/\.ru$/
cfgfile
=
::
File
.
read
(
config
)
if
cfgfile
[
/^#\\(.*)/
]
opts
.
parse!
$1
.
split
(
/\s+/
)
end
inner_app
=
eval
"Rack::Builder.new {( "
+
cfgfile
+
"
\n
)}.to_app"
,
nil
,
config
else
require
config
inner_app
=
Object
.
const_get
(
::
File
.
basename
(
config
,
'.rb'
).
capitalize
)
end
end
end
def
setup
def
setup
build_app
build_app
boot_rails
end
end
test
"rails app is present"
do
test
"rails app is present"
do
...
...
railties/test/boot_test.rb
浏览文件 @
6b086449
...
@@ -62,7 +62,7 @@ class VendorBootTest < Test::Unit::TestCase
...
@@ -62,7 +62,7 @@ class VendorBootTest < Test::Unit::TestCase
def
test_load_initializer_requires_from_vendor_rails
def
test_load_initializer_requires_from_vendor_rails
boot
=
VendorBoot
.
new
boot
=
VendorBoot
.
new
boot
.
expects
(
:require
).
with
(
"rails
/initializer
"
)
boot
.
expects
(
:require
).
with
(
"rails"
)
Rails
::
Initializer
.
expects
(
:run
).
with
(
:install_gem_spec_stubs
)
Rails
::
Initializer
.
expects
(
:run
).
with
(
:install_gem_spec_stubs
)
Rails
::
GemDependency
.
expects
(
:add_frozen_gem_path
)
Rails
::
GemDependency
.
expects
(
:add_frozen_gem_path
)
boot
.
load_initializer
boot
.
load_initializer
...
@@ -76,7 +76,7 @@ def test_load_initializer_loads_rubygems_and_the_rails_gem
...
@@ -76,7 +76,7 @@ def test_load_initializer_loads_rubygems_and_the_rails_gem
boot
=
GemBoot
.
new
boot
=
GemBoot
.
new
GemBoot
.
expects
(
:load_rubygems
)
GemBoot
.
expects
(
:load_rubygems
)
boot
.
expects
(
:load_rails_gem
)
boot
.
expects
(
:load_rails_gem
)
boot
.
expects
(
:require
).
with
(
'rails
/initializer
'
)
boot
.
expects
(
:require
).
with
(
'rails'
)
boot
.
load_initializer
boot
.
load_initializer
end
end
...
...
railties/test/initializer/check_ruby_version_test.rb
浏览文件 @
6b086449
require
"i
nitializer/test_helper
"
require
"i
solation/abstract_unit
"
module
InitializerTests
module
InitializerTests
class
PathsTest
<
Test
::
Unit
::
TestCase
class
PathsTest
<
Test
::
Unit
::
TestCase
include
ActiveSupport
::
Testing
::
Isolation
include
ActiveSupport
::
Testing
::
Isolation
def
setup
build_app
boot_rails
end
test
"rails does not initialize with ruby version 1.8.1"
do
test
"rails does not initialize with ruby version 1.8.1"
do
assert_rails_does_not_boot
"1.8.1"
assert_rails_does_not_boot
"1.8.1"
end
end
...
...
railties/test/initializer/install_gem_spec_stubs_test.rb
已删除
100644 → 0
浏览文件 @
6f6a589d
require
"initializer/test_helper"
module
InitializerTests
class
GemSpecStubsTest
<
Test
::
Unit
::
TestCase
include
ActiveSupport
::
Testing
::
Isolation
def
setup
$stderr
=
StringIO
.
new
end
test
"user has an old boot.rb (defined by having no Rails.vendor_rails?)"
do
class
<<
Rails
undef
vendor_rails?
end
assert_stderr
(
/outdated/
)
do
assert_raises
(
SystemExit
)
do
Rails
::
Initializer
.
run
{
|
c
|
c
.
frameworks
=
[]
}
end
end
end
test
"requires rubygems"
do
Kernel
.
module_eval
do
alias
old_require
require
def
require
(
name
)
$rubygems_required
=
true
if
name
==
"rubygems"
old_require
(
name
)
end
end
Rails
.
vendor_rails
=
true
Rails
::
Initializer
.
run
{
|
c
|
c
.
frameworks
=
[]
}
assert
$rubygems_required
end
# Pending until we're further along
# test "does not fail if rubygems does not exist" do
# Kernel.module_eval do
# alias old_require require
# def require(name)
# raise LoadError if name == "rubygems"
# old_require(name)
# end
# end
#
# assert_nothing_raised do
# Rails::Initializer.run { |c| c.frameworks = [] }
# end
# end
test
"adds fake Rubygems stubs if a framework is not loaded in Rubygems and we've vendored"
do
Rails
.
vendor_rails
=
true
Rails
::
Initializer
.
run
{
|
c
|
c
.
frameworks
=
[]
}
%w(rails activesupport activerecord actionpack actionmailer activeresource)
.
each
do
|
stub
|
gem_spec
=
Gem
.
loaded_specs
[
stub
]
assert_equal
Gem
::
Version
.
new
(
Rails
::
VERSION
::
STRING
),
gem_spec
.
version
assert_equal
stub
,
gem_spec
.
name
assert_equal
""
,
gem_spec
.
loaded_from
end
end
test
"doesn't replace gem specs that are already loaded"
do
Rails
.
vendor_rails
=
true
Gem
.
loaded_specs
[
"rails"
]
=
Gem
::
Specification
.
new
do
|
s
|
s
.
name
=
"rails"
s
.
version
=
Rails
::
VERSION
::
STRING
s
.
loaded_from
=
"/foo/bar/baz"
end
Rails
::
Initializer
.
run
{
|
c
|
c
.
frameworks
=
[]
}
assert_equal
"/foo/bar/baz"
,
Gem
.
loaded_specs
[
"rails"
].
loaded_from
%w(activesupport activerecord actionpack actionmailer activeresource)
.
each
do
|
stub
|
gem_spec
=
Gem
.
loaded_specs
[
stub
]
assert_equal
Gem
::
Version
.
new
(
Rails
::
VERSION
::
STRING
),
gem_spec
.
version
assert_equal
stub
,
gem_spec
.
name
assert_equal
""
,
gem_spec
.
loaded_from
end
end
end
end
\ No newline at end of file
railties/test/initializer/path_test.rb
浏览文件 @
6b086449
require
"i
nitializer/test_helper
"
require
"i
solation/abstract_unit
"
class
PathsTest
<
Test
::
Unit
::
TestCase
class
PathsTest
<
Test
::
Unit
::
TestCase
include
ActiveSupport
::
Testing
::
Isolation
include
ActiveSupport
::
Testing
::
Isolation
def
self
.
setup
def
setup
build_app
boot_rails
Rails
::
Initializer
.
run
do
|
config
|
Rails
::
Initializer
.
run
do
|
config
|
config
.
frameworks
=
[
:action_controller
,
:action_view
,
:action_mailer
,
:active_record
]
config
.
frameworks
=
[
:action_controller
,
:action_view
,
:action_mailer
,
:active_record
]
config
.
after_initialize
do
config
.
after_initialize
do
ActionController
::
Base
.
session_store
=
nil
ActionController
::
Base
.
session_store
=
nil
end
end
end
end
end
def
setup
@paths
=
Rails
::
Initializer
.
default
.
config
.
paths
@paths
=
Rails
::
Initializer
.
default
.
config
.
paths
end
end
def
root
(
*
path
)
def
root
(
*
path
)
File
.
expand_path
(
File
.
join
(
File
.
dirname
(
__FILE__
),
"root"
,
*
path
))
app_path
(
*
path
).
to_s
end
end
def
assert_path
(
paths
,
*
dir
)
def
assert_path
(
paths
,
*
dir
)
assert_equal
[
root
(
*
dir
)],
paths
.
paths
assert_equal
[
root
(
*
dir
)],
paths
.
paths
end
end
def
assert_in_load_path
(
*
path
)
assert
$:
.
any?
{
|
p
|
File
.
expand_path
(
p
)
==
root
(
*
path
)
},
"Load path does not include '
#{
root
(
*
path
)
}
'. They are:
\n
-----
\n
#{
$:
.
join
(
"
\n
"
)
}
\n
-----"
end
def
assert_not_in_load_path
(
*
path
)
assert
!
$:
.
any?
{
|
p
|
File
.
expand_path
(
p
)
==
root
(
*
path
)
},
"Load path includes '
#{
root
(
*
path
)
}
'. They are:
\n
-----
\n
#{
$:
.
join
(
"
\n
"
)
}
\n
-----"
end
test
"booting up Rails yields a valid paths object"
do
test
"booting up Rails yields a valid paths object"
do
assert_path
@paths
.
app
,
"app"
assert_path
@paths
.
app
,
"app"
assert_path
@paths
.
app
.
metals
,
"app"
,
"metal"
assert_path
@paths
.
app
.
metals
,
"app"
,
"metal"
...
@@ -39,8 +46,7 @@ def assert_path(paths, *dir)
...
@@ -39,8 +46,7 @@ def assert_path(paths, *dir)
assert_path
@paths
.
config
.
locales
,
"config"
,
"locales"
assert_path
@paths
.
config
.
locales
,
"config"
,
"locales"
assert_path
@paths
.
config
.
environments
,
"config"
,
"environments"
assert_path
@paths
.
config
.
environments
,
"config"
,
"environments"
assert_equal
Pathname
.
new
(
File
.
dirname
(
__FILE__
)).
join
(
"root"
,
"app"
,
"controllers"
).
expand_path
,
assert_equal
root
(
"app"
,
"controllers"
),
@paths
.
app
.
controllers
.
to_a
.
first
Pathname
.
new
(
@paths
.
app
.
controllers
.
to_a
.
first
).
expand_path
assert_equal
Pathname
.
new
(
File
.
dirname
(
__FILE__
)).
join
(
".."
,
".."
,
"builtin"
,
"rails_info"
).
expand_path
,
assert_equal
Pathname
.
new
(
File
.
dirname
(
__FILE__
)).
join
(
".."
,
".."
,
"builtin"
,
"rails_info"
).
expand_path
,
Pathname
.
new
(
@paths
.
app
.
controllers
.
to_a
[
1
]).
expand_path
Pathname
.
new
(
@paths
.
app
.
controllers
.
to_a
[
1
]).
expand_path
end
end
...
@@ -56,24 +62,16 @@ def assert_path(paths, *dir)
...
@@ -56,24 +62,16 @@ def assert_path(paths, *dir)
assert_equal
"
#{
RAILS_ENV
}
.rb"
,
@paths
.
config
.
environments
.
glob
assert_equal
"
#{
RAILS_ENV
}
.rb"
,
@paths
.
config
.
environments
.
glob
end
end
def
assert_in_load_path
(
*
path
)
assert
$:
.
any?
{
|
p
|
File
.
expand_path
(
p
)
==
root
(
*
path
)
},
"Load path does not include '
#{
root
(
*
path
)
}
'. They are:
\n
-----
\n
#{
$:
.
join
(
"
\n
"
)
}
\n
-----"
end
def
assert_not_in_load_path
(
*
path
)
assert
!
$:
.
any?
{
|
p
|
File
.
expand_path
(
p
)
==
root
(
*
path
)
},
"Load path includes '
#{
root
(
*
path
)
}
'. They are:
\n
-----
\n
#{
$:
.
join
(
"
\n
"
)
}
\n
-----"
end
test
"load path includes each of the paths in config.paths as long as the directories exist"
do
test
"load path includes each of the paths in config.paths as long as the directories exist"
do
assert_in_load_path
"app"
assert_in_load_path
"app"
assert_in_load_path
"app"
,
"controllers"
assert_in_load_path
"app"
,
"controllers"
assert_in_load_path
"app"
,
"metal"
assert_in_load_path
"app"
,
"models"
assert_in_load_path
"app"
,
"models"
assert_in_load_path
"app"
,
"helpers"
assert_in_load_path
"app"
,
"helpers"
assert_in_load_path
"lib"
assert_in_load_path
"lib"
assert_in_load_path
"vendor"
assert_in_load_path
"vendor"
assert_not_in_load_path
"app"
,
"views"
assert_not_in_load_path
"app"
,
"views"
assert_not_in_load_path
"app"
,
"metal"
assert_not_in_load_path
"app"
,
"services"
assert_not_in_load_path
"app"
,
"services"
assert_not_in_load_path
"config"
assert_not_in_load_path
"config"
assert_not_in_load_path
"config"
,
"locales"
assert_not_in_load_path
"config"
,
"locales"
...
...
railties/test/isolation/abstract_unit.rb
浏览文件 @
6b086449
...
@@ -14,10 +14,6 @@
...
@@ -14,10 +14,6 @@
# TODO: Remove setting this magic constant
# TODO: Remove setting this magic constant
RAILS_FRAMEWORK_ROOT
=
File
.
expand_path
(
"
#{
File
.
dirname
(
__FILE__
)
}
/../../.."
)
RAILS_FRAMEWORK_ROOT
=
File
.
expand_path
(
"
#{
File
.
dirname
(
__FILE__
)
}
/../../.."
)
# These load paths usually get set inside of boot.rb
$:
.
unshift
"
#{
RAILS_FRAMEWORK_ROOT
}
/railties/lib"
$:
.
unshift
"
#{
RAILS_FRAMEWORK_ROOT
}
/actionpack/lib"
# These files do not require any others and are needed
# These files do not require any others and are needed
# to run the tests
# to run the tests
require
"
#{
RAILS_FRAMEWORK_ROOT
}
/activesupport/lib/active_support/testing/isolation"
require
"
#{
RAILS_FRAMEWORK_ROOT
}
/activesupport/lib/active_support/testing/isolation"
...
@@ -71,8 +67,23 @@ def assert_body(expected, resp)
...
@@ -71,8 +67,23 @@ def assert_body(expected, resp)
end
end
module
Generation
module
Generation
def
build_app
def
build_app
(
options
=
{})
FileUtils
.
rm_rf
(
app_path
)
FileUtils
.
cp_r
(
tmp_path
(
'app_template'
),
app_path
)
FileUtils
.
cp_r
(
tmp_path
(
'app_template'
),
app_path
)
# Delete the initializers unless requested
unless
options
[
:initializers
]
Dir
[
"
#{
app_path
}
/config/initializers/*.rb"
].
each
do
|
initializer
|
File
.
delete
(
initializer
)
end
end
environment
=
File
.
read
(
"
#{
app_path
}
/config/environment.rb"
)
if
environment
=~
/(\n\s*end\s*)\Z/
File
.
open
(
"
#{
app_path
}
/config/environment.rb"
,
'w'
)
do
|
f
|
f
.
puts
$`
+
%'\nconfig.action_controller.session = { :key => "_myapp_session", :secret => "bac838a849c1d5c4de2e6a50af826079" }\n'
+
$1
end
end
end
end
def
app_file
(
path
,
contents
)
def
app_file
(
path
,
contents
)
...
@@ -84,6 +95,23 @@ def app_file(path, contents)
...
@@ -84,6 +95,23 @@ def app_file(path, contents)
def
controller
(
name
,
contents
)
def
controller
(
name
,
contents
)
app_file
(
"app/controllers/
#{
name
}
_controller.rb"
,
contents
)
app_file
(
"app/controllers/
#{
name
}
_controller.rb"
,
contents
)
end
end
def
boot_rails
# return if defined?(RAILS)
# TODO: Get this working with boot.rb
$:
.
unshift
"
#{
RAILS_FRAMEWORK_ROOT
}
/railties/lib"
Object
.
class_eval
<<-
RUBY
RAILS_ROOT = "
#{
app_path
}
"
module ::Rails
def self.vendor_rails?
true
end
end
RUBY
require
"rails"
Rails
::
Initializer
.
run
(
:install_gem_spec_stubs
)
Rails
::
GemDependency
.
add_frozen_gem_path
end
end
end
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录