Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
e7418ab6
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,发现更多精彩内容 >>
提交
e7418ab6
编写于
1月 27, 2010
作者:
J
José Valim
提交者:
Carl Lerche
1月 28, 2010
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add more tests to some key points in Railties.
Signed-off-by:
N
Carl Lerche
<
carllerche@mac.com
>
上级
64ea3dfd
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
190 addition
and
48 deletion
+190
-48
railties/lib/rails/application.rb
railties/lib/rails/application.rb
+4
-0
railties/test/application/configuration_test.rb
railties/test/application/configuration_test.rb
+10
-1
railties/test/application/initializers/frameworks_test.rb
railties/test/application/initializers/frameworks_test.rb
+6
-0
railties/test/application/initializers/load_path_test.rb
railties/test/application/initializers/load_path_test.rb
+14
-2
railties/test/railties/configuration_test.rb
railties/test/railties/configuration_test.rb
+0
-45
railties/test/railties/engine_test.rb
railties/test/railties/engine_test.rb
+4
-0
railties/test/railties/plugin_test.rb
railties/test/railties/plugin_test.rb
+11
-0
railties/test/railties/railtie_test.rb
railties/test/railties/railtie_test.rb
+132
-0
railties/test/railties/shared_tests.rb
railties/test/railties/shared_tests.rb
+9
-0
未找到文件。
railties/lib/rails/application.rb
浏览文件 @
e7418ab6
...
...
@@ -31,6 +31,10 @@ def inherited(base)
Rails
.
application
=
base
.
instance
end
def
respond_to?
(
*
args
)
super
||
instance
.
respond_to?
(
*
args
)
end
protected
def
method_missing
(
*
args
,
&
block
)
...
...
railties/test/application/configuration_test.rb
浏览文件 @
e7418ab6
...
...
@@ -17,12 +17,15 @@ def app
end
def
setup
FileUtils
.
rm_rf
(
new_app
)
if
File
.
directory?
(
new_app
)
build_app
boot_rails
FileUtils
.
rm_rf
(
"
#{
app_path
}
/config/environments"
)
end
def
teardown
FileUtils
.
rm_rf
(
new_app
)
if
File
.
directory?
(
new_app
)
end
test
"Rails::Application.instance is nil until app is initialized"
do
require
'rails'
assert_nil
Rails
::
Application
.
instance
...
...
@@ -30,6 +33,12 @@ def setup
assert_equal
AppTemplate
::
Application
.
instance
,
Rails
::
Application
.
instance
end
test
"Rails::Application responds to all instance methods"
do
require
"
#{
app_path
}
/config/environment"
assert_respond_to
Rails
::
Application
,
:routes_reloader
assert_equal
Rails
::
Application
.
routes_reloader
,
Rails
.
application
.
routes_reloader
end
test
"the application root is set correctly"
do
require
"
#{
app_path
}
/config/environment"
assert_equal
Pathname
.
new
(
app_path
),
Rails
.
application
.
root
...
...
railties/test/application/initializers/frameworks_test.rb
浏览文件 @
e7418ab6
...
...
@@ -71,6 +71,12 @@ def setup
assert_equal
expects
,
middleware
&
expects
end
test
"active_record extensions are applied to ActiveRecord"
do
add_to_config
"config.active_record.table_name_prefix = 'tbl_'"
require
"
#{
app_path
}
/config/environment"
assert_equal
'tbl_'
,
ActiveRecord
::
Base
.
table_name_prefix
end
test
"database middleware doesn't initialize when activerecord is not in frameworks"
do
use_frameworks
[]
require
"
#{
app_path
}
/config/environment"
...
...
railties/test/application/initializers/load_path_test.rb
浏览文件 @
e7418ab6
...
...
@@ -10,7 +10,6 @@ def setup
FileUtils
.
rm_rf
"
#{
app_path
}
/config/environments"
end
# General
test
"initializing an application adds the application paths to the load path"
do
add_to_config
<<-
RUBY
config.root = "
#{
app_path
}
"
...
...
@@ -20,10 +19,24 @@ def setup
assert
$:
.
include?
(
"
#{
app_path
}
/app/models"
)
end
test
"initializing an application eager load any path under app"
do
app_file
"app/anything/foo.rb"
,
<<-
RUBY
module Foo; end
RUBY
add_to_config
<<-
RUBY
config.root = "
#{
app_path
}
"
RUBY
require
"
#{
app_path
}
/config/environment"
assert
Foo
end
test
"eager loading loads parent classes before children"
do
app_file
"lib/zoo.rb"
,
<<-
ZOO
class Zoo ; include ReptileHouse ; end
ZOO
app_file
"lib/zoo/reptile_house.rb"
,
<<-
ZOO
module Zoo::ReptileHouse ; end
ZOO
...
...
@@ -34,7 +47,6 @@ module Zoo::ReptileHouse ; end
RUBY
require
"
#{
app_path
}
/config/environment"
assert
Zoo
end
...
...
railties/test/railties/configuration_test.rb
已删除
100644 → 0
浏览文件 @
64ea3dfd
require
"isolation/abstract_unit"
module
RailtiesTest
class
ConfigurationTest
<
Test
::
Unit
::
TestCase
def
setup
build_app
boot_rails
require
"rails/all"
end
test
"config is available to plugins"
do
class
Foo
<
Rails
::
Railtie
;
end
assert_nil
Foo
.
config
.
action_controller
.
foo
end
test
"a config name is available for the plugin"
do
class
Foo
<
Rails
::
Railtie
;
config
.
foo
.
greetings
=
"hello"
;
end
assert_equal
"hello"
,
Foo
.
config
.
foo
.
greetings
end
test
"railtie configurations are available in the application"
do
class
Foo
<
Rails
::
Railtie
;
config
.
foo
.
greetings
=
"hello"
;
end
require
"
#{
app_path
}
/config/application"
assert_equal
"hello"
,
AppTemplate
::
Application
.
config
.
foo
.
greetings
end
test
"railtie config merges are deep"
do
class
Foo
<
Rails
::
Railtie
;
config
.
foo
.
greetings
=
'hello'
;
end
class
Bar
<
Rails
::
Railtie
config
.
foo
.
bar
=
"bar"
end
assert_equal
"hello"
,
Bar
.
config
.
foo
.
greetings
assert_equal
"bar"
,
Bar
.
config
.
foo
.
bar
end
test
"railtie can add subscribers"
do
begin
class
Foo
<
Rails
::
Railtie
;
subscriber
(
Rails
::
Subscriber
.
new
);
end
assert_kind_of
Rails
::
Subscriber
,
Rails
::
Subscriber
.
subscribers
[
:foo
]
ensure
Rails
::
Subscriber
.
subscribers
.
clear
end
end
end
end
railties/test/railties/engine_test.rb
浏览文件 @
e7418ab6
...
...
@@ -23,5 +23,9 @@ class Engine < ::Rails::Engine
def
reload_config
:reload_engines
end
test
"Rails::Engine itself does not respond to config"
do
assert
!
Rails
::
Engine
.
respond_to?
(
:config
)
end
end
end
railties/test/railties/plugin_test.rb
浏览文件 @
e7418ab6
...
...
@@ -19,6 +19,17 @@ def reload_config
:reload_plugins
end
test
"Rails::Plugin itself does not respond to config"
do
assert
!
Rails
::
Plugin
.
respond_to?
(
:config
)
end
test
"cannot inherit from Rails::Plugin"
do
boot_rails
assert_raise
RuntimeError
do
class
Foo
<
Rails
::
Plugin
;
end
end
end
test
"plugin can load the file with the same name in lib"
do
boot_rails
require
"bukkits"
...
...
railties/test/railties/
framework_extension
_test.rb
→
railties/test/railties/
railtie
_test.rb
浏览文件 @
e7418ab6
require
"isolation/abstract_unit"
module
RailtiesTest
class
FrameworkExtension
Test
<
Test
::
Unit
::
TestCase
class
Railtie
Test
<
Test
::
Unit
::
TestCase
include
ActiveSupport
::
Testing
::
Isolation
def
setup
...
...
@@ -11,6 +11,74 @@ def setup
require
"rails/all"
end
def
app
@app
||=
Rails
.
application
end
test
"Rails::Railtie itself does not respond to config"
do
assert
!
Rails
::
Railtie
.
respond_to?
(
:config
)
end
test
"cannot inherit from a railtie"
do
class
Foo
<
Rails
::
Railtie
;
end
assert_raise
RuntimeError
do
class
Bar
<
Foo
;
end
end
end
test
"config is available to railtie"
do
class
Foo
<
Rails
::
Railtie
;
end
assert_nil
Foo
.
config
.
action_controller
.
foo
end
test
"config name is available for the railtie"
do
class
Foo
<
Rails
::
Railtie
;
config
.
foo
.
greetings
=
"hello"
;
end
assert_equal
"hello"
,
Foo
.
config
.
foo
.
greetings
end
test
"railtie configurations are available in the application"
do
class
Foo
<
Rails
::
Railtie
;
config
.
foo
.
greetings
=
"hello"
;
end
require
"
#{
app_path
}
/config/application"
assert_equal
"hello"
,
AppTemplate
::
Application
.
config
.
foo
.
greetings
end
test
"railtie config merges are deep"
do
class
Foo
<
Rails
::
Railtie
;
config
.
foo
.
greetings
=
'hello'
;
end
class
Bar
<
Rails
::
Railtie
config
.
foo
.
bar
=
"bar"
end
assert_equal
"hello"
,
Bar
.
config
.
foo
.
greetings
assert_equal
"bar"
,
Bar
.
config
.
foo
.
bar
end
test
"railtie can add subscribers"
do
begin
class
Foo
<
Rails
::
Railtie
;
subscriber
(
Rails
::
Subscriber
.
new
)
;
end
assert_kind_of
Rails
::
Subscriber
,
Rails
::
Subscriber
.
subscribers
[
:foo
]
ensure
Rails
::
Subscriber
.
subscribers
.
clear
end
end
test
"railtie can add to_prepare callbacks"
do
$to_prepare
=
false
class
Foo
<
Rails
::
Railtie
;
config
.
to_prepare
{
$to_prepare
=
true
}
;
end
assert
!
$to_prepare
require
"
#{
app_path
}
/config/environment"
require
"rack/test"
extend
Rack
::
Test
::
Methods
get
"/"
assert
$to_prepare
end
test
"railtie can add after_initialize callbacks"
do
$after_initialize
=
false
class
Foo
<
Rails
::
Railtie
;
config
.
after_initialize
{
$after_initialize
=
true
}
;
end
assert
!
$after_initialize
require
"
#{
app_path
}
/config/environment"
assert
$after_initialize
end
test
"rake_tasks block is executed when MyApp.load_tasks is called"
do
$ran_block
=
false
...
...
@@ -47,7 +115,7 @@ class MyTie < Rails::Railtie
assert
$ran_block
end
test
"railtie
initializer
"
do
test
"railtie
can add initializers
"
do
$ran_block
=
false
class
MyTie
<
Rails
::
Railtie
...
...
@@ -61,22 +129,4 @@ class MyTie < Rails::Railtie
assert
$ran_block
end
end
class
ActiveRecordExtensionTest
<
Test
::
Unit
::
TestCase
include
ActiveSupport
::
Testing
::
Isolation
def
setup
build_app
boot_rails
FileUtils
.
rm_rf
(
"
#{
app_path
}
/config/environments"
)
end
test
"active_record extensions are applied to ActiveRecord"
do
add_to_config
"config.active_record.table_name_prefix = 'tbl_'"
require
"
#{
app_path
}
/config/environment"
assert_equal
'tbl_'
,
ActiveRecord
::
Base
.
table_name_prefix
end
end
end
\ No newline at end of file
end
railties/test/railties/shared_tests.rb
浏览文件 @
e7418ab6
...
...
@@ -116,6 +116,15 @@ def bukkits
assert_equal
"Hello bukkits
\n
"
,
response
[
2
].
body
end
def
test_plugin_eager_load_any_path_under_app
@plugin
.
write
"app/anything/foo.rb"
,
<<-
RUBY
module Foo; end
RUBY
boot_rails
assert
Foo
end
def
test_routes_are_added_to_router
@plugin
.
write
"config/routes.rb"
,
<<-
RUBY
class Sprokkit
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录