Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
ee0879f6
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,发现更多精彩内容 >>
提交
ee0879f6
编写于
3月 09, 2012
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5356 from carlosantoniodasilva/rake-test-system
Use one system call whenever possible, group rake and Dir.chdir calls
上级
74d5d9a3
73e8e700
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
98 addition
and
106 deletion
+98
-106
railties/test/application/initializers/frameworks_test.rb
railties/test/application/initializers/frameworks_test.rb
+4
-9
railties/test/application/rake/migrations_test.rb
railties/test/application/rake/migrations_test.rb
+82
-81
railties/test/application/rake/notes_test.rb
railties/test/application/rake/notes_test.rb
+1
-2
railties/test/application/rake_test.rb
railties/test/application/rake_test.rb
+11
-14
未找到文件。
railties/test/application/initializers/frameworks_test.rb
浏览文件 @
ee0879f6
...
...
@@ -196,9 +196,8 @@ def from_bar_helper
test
"use schema cache dump"
do
Dir
.
chdir
(
app_path
)
do
`rails generate model post title:string`
`bundle exec rake db:migrate`
`bundle exec rake db:schema:cache:dump`
`rails generate model post title:string;
bundle exec rake db:migrate db:schema:cache:dump`
end
require
"
#{
app_path
}
/config/environment"
ActiveRecord
::
Base
.
connection
.
drop_table
(
"posts"
)
# force drop posts table for test.
...
...
@@ -207,17 +206,13 @@ def from_bar_helper
test
"expire schema cache dump"
do
Dir
.
chdir
(
app_path
)
do
`rails generate model post title:string`
`bundle exec rake db:migrate`
`bundle exec rake db:schema:cache:dump`
`bundle exec rake db:rollback`
`rails generate model post title:string;
bundle exec rake db:migrate db:schema:cache:dump db:rollback`
end
silence_warnings
{
require
"
#{
app_path
}
/config/environment"
assert
!
ActiveRecord
::
Base
.
connection
.
schema_cache
.
tables
[
"posts"
]
}
end
end
end
railties/test/application/rake/migrations_test.rb
浏览文件 @
ee0879f6
...
...
@@ -16,44 +16,45 @@ def teardown
test
'running migrations with given scope'
do
Dir
.
chdir
(
app_path
)
do
`rails generate model user username:string password:string`
end
app_file
"db/migrate/01_a_migration.bukkits.rb"
,
<<-
MIGRATION
class AMigration < ActiveRecord::Migration
end
MIGRATION
output
=
Dir
.
chdir
(
app_path
)
{
`rake db:migrate SCOPE=bukkits`
}
assert_no_match
(
/create_table\(:users\)/
,
output
)
assert_no_match
(
/CreateUsers/
,
output
)
assert_no_match
(
/add_column\(:users, :email, :string\)/
,
output
)
app_file
"db/migrate/01_a_migration.bukkits.rb"
,
<<-
MIGRATION
class AMigration < ActiveRecord::Migration
end
MIGRATION
output
=
`rake db:migrate SCOPE=bukkits`
assert_no_match
(
/create_table\(:users\)/
,
output
)
assert_no_match
(
/CreateUsers/
,
output
)
assert_no_match
(
/add_column\(:users, :email, :string\)/
,
output
)
assert_match
(
/AMigration: migrated/
,
output
)
assert_match
(
/AMigration: migrated/
,
output
)
output
=
Dir
.
chdir
(
app_path
)
{
`rake db:migrate SCOPE=bukkits VERSION=0`
}
assert_no_match
(
/drop_table\(:users\)/
,
output
)
assert_no_match
(
/CreateUsers/
,
output
)
assert_no_match
(
/remove_column\(:users, :email\)/
,
output
)
output
=
`rake db:migrate SCOPE=bukkits VERSION=0`
assert_no_match
(
/drop_table\(:users\)/
,
output
)
assert_no_match
(
/CreateUsers/
,
output
)
assert_no_match
(
/remove_column\(:users, :email\)/
,
output
)
assert_match
(
/AMigration: reverted/
,
output
)
assert_match
(
/AMigration: reverted/
,
output
)
end
end
test
'model and migration generator with change syntax'
do
Dir
.
chdir
(
app_path
)
do
`rails generate model user username:string password:string`
`rails generate migration add_email_to_users email:string`
`rails generate model user username:string password:string;
rails generate migration add_email_to_users email:string`
output
=
`rake db:migrate`
assert_match
(
/create_table\(:users\)/
,
output
)
assert_match
(
/CreateUsers: migrated/
,
output
)
assert_match
(
/add_column\(:users, :email, :string\)/
,
output
)
assert_match
(
/AddEmailToUsers: migrated/
,
output
)
output
=
`rake db:rollback STEP=2`
assert_match
(
/drop_table\("users"\)/
,
output
)
assert_match
(
/CreateUsers: reverted/
,
output
)
assert_match
(
/remove_column\("users", :email\)/
,
output
)
assert_match
(
/AddEmailToUsers: reverted/
,
output
)
end
output
=
Dir
.
chdir
(
app_path
){
`rake db:migrate`
}
assert_match
(
/create_table\(:users\)/
,
output
)
assert_match
(
/CreateUsers: migrated/
,
output
)
assert_match
(
/add_column\(:users, :email, :string\)/
,
output
)
assert_match
(
/AddEmailToUsers: migrated/
,
output
)
output
=
Dir
.
chdir
(
app_path
){
`rake db:rollback STEP=2`
}
assert_match
(
/drop_table\("users"\)/
,
output
)
assert_match
(
/CreateUsers: reverted/
,
output
)
assert_match
(
/remove_column\("users", :email\)/
,
output
)
assert_match
(
/AddEmailToUsers: reverted/
,
output
)
end
test
'migration status when schema migrations table is not present'
do
...
...
@@ -63,94 +64,94 @@ class AMigration < ActiveRecord::Migration
test
'test migration status'
do
Dir
.
chdir
(
app_path
)
do
`rails generate model user username:string password:string
`
`rails generate migration add_email_to_users email:string`
end
`rails generate model user username:string password:string
;
rails generate migration add_email_to_users email:string;
rake db:migrate`
Dir
.
chdir
(
app_path
)
{
`rake db:migrate`
}
output
=
Dir
.
chdir
(
app_path
)
{
`rake db:migrate:status`
}
output
=
`rake db:migrate:status`
assert_match
(
/up\s+\d{14}\s+Create users/
,
output
)
assert_match
(
/up\s+\d{14}\s+Add email to users/
,
output
)
assert_match
(
/up\s+\d{14}\s+Create users/
,
output
)
assert_match
(
/up\s+\d{14}\s+Add email to users/
,
output
)
Dir
.
chdir
(
app_path
)
{
`rake db:rollback STEP=1`
}
output
=
Dir
.
chdir
(
app_path
)
{
`rake db:migrate:status`
}
`rake db:rollback STEP=1`
output
=
`rake db:migrate:status`
assert_match
(
/up\s+\d{14}\s+Create users/
,
output
)
assert_match
(
/down\s+\d{14}\s+Add email to users/
,
output
)
assert_match
(
/up\s+\d{14}\s+Create users/
,
output
)
assert_match
(
/down\s+\d{14}\s+Add email to users/
,
output
)
end
end
test
'migration status without timestamps'
do
add_to_config
(
'config.active_record.timestamped_migrations = false'
)
Dir
.
chdir
(
app_path
)
do
`rails generate model user username:string password:string
`
`rails generate migration add_email_to_users email:string`
end
`rails generate model user username:string password:string
;
rails generate migration add_email_to_users email:string;
rake db:migrate`
Dir
.
chdir
(
app_path
)
{
`rake db:migrate`
}
output
=
Dir
.
chdir
(
app_path
)
{
`rake db:migrate:status`
}
output
=
`rake db:migrate:status`
assert_match
(
/up\s+\d{3,}\s+Create users/
,
output
)
assert_match
(
/up\s+\d{3,}\s+Add email to users/
,
output
)
assert_match
(
/up\s+\d{3,}\s+Create users/
,
output
)
assert_match
(
/up\s+\d{3,}\s+Add email to users/
,
output
)
Dir
.
chdir
(
app_path
)
{
`rake db:rollback STEP=1`
}
output
=
Dir
.
chdir
(
app_path
)
{
`rake db:migrate:status`
}
`rake db:rollback STEP=1`
output
=
`rake db:migrate:status`
assert_match
(
/up\s+\d{3,}\s+Create users/
,
output
)
assert_match
(
/down\s+\d{3,}\s+Add email to users/
,
output
)
assert_match
(
/up\s+\d{3,}\s+Create users/
,
output
)
assert_match
(
/down\s+\d{3,}\s+Add email to users/
,
output
)
end
end
test
'test migration status after rollback and redo'
do
Dir
.
chdir
(
app_path
)
do
`rails generate model user username:string password:string
`
`rails generate migration add_email_to_users email:string`
end
`rails generate model user username:string password:string
;
rails generate migration add_email_to_users email:string;
rake db:migrate`
Dir
.
chdir
(
app_path
)
{
`rake db:migrate`
}
output
=
Dir
.
chdir
(
app_path
)
{
`rake db:migrate:status`
}
output
=
`rake db:migrate:status`
assert_match
(
/up\s+\d{14}\s+Create users/
,
output
)
assert_match
(
/up\s+\d{14}\s+Add email to users/
,
output
)
assert_match
(
/up\s+\d{14}\s+Create users/
,
output
)
assert_match
(
/up\s+\d{14}\s+Add email to users/
,
output
)
Dir
.
chdir
(
app_path
)
{
`rake db:rollback STEP=2`
}
output
=
Dir
.
chdir
(
app_path
)
{
`rake db:migrate:status`
}
`rake db:rollback STEP=2`
output
=
`rake db:migrate:status`
assert_match
(
/down\s+\d{14}\s+Create users/
,
output
)
assert_match
(
/down\s+\d{14}\s+Add email to users/
,
output
)
assert_match
(
/down\s+\d{14}\s+Create users/
,
output
)
assert_match
(
/down\s+\d{14}\s+Add email to users/
,
output
)
Dir
.
chdir
(
app_path
)
{
`rake db:migrate:redo`
}
output
=
Dir
.
chdir
(
app_path
)
{
`rake db:migrate:status`
}
`rake db:migrate:redo`
output
=
`rake db:migrate:status`
assert_match
(
/up\s+\d{14}\s+Create users/
,
output
)
assert_match
(
/up\s+\d{14}\s+Add email to users/
,
output
)
assert_match
(
/up\s+\d{14}\s+Create users/
,
output
)
assert_match
(
/up\s+\d{14}\s+Add email to users/
,
output
)
end
end
test
'migration status after rollback and redo without timestamps'
do
add_to_config
(
'config.active_record.timestamped_migrations = false'
)
Dir
.
chdir
(
app_path
)
do
`rails generate model user username:string password:string
`
`rails generate migration add_email_to_users email:string`
end
`rails generate model user username:string password:string
;
rails generate migration add_email_to_users email:string;
rake db:migrate`
Dir
.
chdir
(
app_path
)
{
`rake db:migrate`
}
output
=
Dir
.
chdir
(
app_path
)
{
`rake db:migrate:status`
}
output
=
`rake db:migrate:status`
assert_match
(
/up\s+\d{3,}\s+Create users/
,
output
)
assert_match
(
/up\s+\d{3,}\s+Add email to users/
,
output
)
assert_match
(
/up\s+\d{3,}\s+Create users/
,
output
)
assert_match
(
/up\s+\d{3,}\s+Add email to users/
,
output
)
Dir
.
chdir
(
app_path
)
{
`rake db:rollback STEP=2`
}
output
=
Dir
.
chdir
(
app_path
)
{
`rake db:migrate:status`
}
`rake db:rollback STEP=2`
output
=
`rake db:migrate:status`
assert_match
(
/down\s+\d{3,}\s+Create users/
,
output
)
assert_match
(
/down\s+\d{3,}\s+Add email to users/
,
output
)
assert_match
(
/down\s+\d{3,}\s+Create users/
,
output
)
assert_match
(
/down\s+\d{3,}\s+Add email to users/
,
output
)
Dir
.
chdir
(
app_path
)
{
`rake db:migrate:redo`
}
output
=
Dir
.
chdir
(
app_path
)
{
`rake db:migrate:status`
}
`rake db:migrate:redo`
output
=
`rake db:migrate:status`
assert_match
(
/up\s+\d{3,}\s+Create users/
,
output
)
assert_match
(
/up\s+\d{3,}\s+Add email to users/
,
output
)
assert_match
(
/up\s+\d{3,}\s+Create users/
,
output
)
assert_match
(
/up\s+\d{3,}\s+Add email to users/
,
output
)
end
end
end
end
...
...
railties/test/application/rake/notes_test.rb
浏览文件 @
ee0879f6
...
...
@@ -3,7 +3,7 @@
module
ApplicationTests
module
RakeTests
class
RakeNotesTest
<
ActiveSupport
::
TestCase
def
setup
def
setup
build_app
require
"rails/all"
end
...
...
@@ -13,7 +13,6 @@ def teardown
end
test
'notes'
do
app_file
"app/views/home/index.html.erb"
,
"<% # TODO: note in erb %>"
app_file
"app/views/home/index.html.haml"
,
"-# TODO: note in haml"
app_file
"app/views/home/index.html.slim"
,
"/ TODO: note in slim"
...
...
railties/test/application/rake_test.rb
浏览文件 @
ee0879f6
...
...
@@ -107,9 +107,9 @@ def test_logger_is_flushed_when_exiting_production_rake_tasks
def
test_loading_specific_fixtures
Dir
.
chdir
(
app_path
)
do
`rails generate model user username:string password:string
`
`rails generate model product name:string`
`
rake db:migrate`
`rails generate model user username:string password:string
;
rails generate model product name:string;
rake db:migrate`
end
require
"
#{
rails_root
}
/config/environment"
...
...
@@ -124,8 +124,8 @@ def test_loading_specific_fixtures
def
test_scaffold_tests_pass_by_default
content
=
Dir
.
chdir
(
app_path
)
do
`rails generate scaffold user username:string password:string
`
`
bundle exec rake db:migrate db:test:clone test`
`rails generate scaffold user username:string password:string
;
bundle exec rake db:migrate db:test:clone test`
end
assert_match
(
/\d+ tests, \d+ assertions, 0 failures, 0 errors/
,
content
)
...
...
@@ -133,29 +133,26 @@ def test_scaffold_tests_pass_by_default
def
test_rake_dump_structure_should_respect_db_structure_env_variable
Dir
.
chdir
(
app_path
)
do
`bundle exec rake db:migrate`
# ensure we have a schema_migrations table to dump
`bundle exec rake db:structure:dump DB_STRUCTURE=db/my_structure.sql`
# ensure we have a schema_migrations table to dump
`bundle exec rake db:
migrate db:
structure:dump DB_STRUCTURE=db/my_structure.sql`
end
assert
File
.
exists?
(
File
.
join
(
app_path
,
'db'
,
'my_structure.sql'
))
end
def
test_rake_dump_schema_cache
Dir
.
chdir
(
app_path
)
do
`rails generate model post title:string`
`rails generate model product name:string`
`bundle exec rake db:migrate`
`bundle exec rake db:schema:cache:dump`
`rails generate model post title:string;
rails generate model product name:string;
bundle exec rake db:migrate db:schema:cache:dump`
end
assert
File
.
exists?
(
File
.
join
(
app_path
,
'db'
,
'schema_cache.dump'
))
end
def
test_rake_clear_schema_cache
Dir
.
chdir
(
app_path
)
do
`bundle exec rake db:schema:cache:dump`
`bundle exec rake db:schema:cache:clear`
`bundle exec rake db:schema:cache:dump db:schema:cache:clear`
end
assert
!
File
.
exists?
(
File
.
join
(
app_path
,
'db'
,
'schema_cache.dump'
))
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录