Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
ac1ee519
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,发现更多精彩内容 >>
提交
ac1ee519
编写于
10月 10, 2017
作者:
M
Matthew Draper
提交者:
GitHub
10月 10, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #30595 from bogdanvlviv/use-railties-rails-command
Improve railties' tests
上级
1b36e2cc
2329207b
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
207 addition
and
249 deletion
+207
-249
railties/test/application/dbconsole_test.rb
railties/test/application/dbconsole_test.rb
+24
-28
railties/test/application/loading_test.rb
railties/test/application/loading_test.rb
+2
-2
railties/test/application/rake/dbs_test.rb
railties/test/application/rake/dbs_test.rb
+48
-59
railties/test/application/rake/migrations_test.rb
railties/test/application/rake/migrations_test.rb
+115
-134
railties/test/application/rake_test.rb
railties/test/application/rake_test.rb
+17
-25
railties/test/application/server_test.rb
railties/test/application/server_test.rb
+1
-1
未找到文件。
railties/test/application/dbconsole_test.rb
浏览文件 @
ac1ee519
...
...
@@ -19,21 +19,19 @@ def teardown
end
def
test_use_value_defined_in_environment_file_in_database_yml
Dir
.
chdir
(
app_path
)
do
app_file
"config/database.yml"
,
<<-
YAML
development:
database: <%= Rails.application.config.database %>
adapter: sqlite3
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
YAML
app_file
"config/database.yml"
,
<<-
YAML
development:
database: <%= Rails.application.config.database %>
adapter: sqlite3
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
YAML
app_file
"config/environments/development.rb"
,
<<-
RUBY
Rails.application.configure do
config.database = "db/development.sqlite3"
end
RUBY
end
app_file
"config/environments/development.rb"
,
<<-
RUBY
Rails.application.configure do
config.database = "db/development.sqlite3"
end
RUBY
master
,
slave
=
PTY
.
open
spawn_dbconsole
(
slave
)
...
...
@@ -43,22 +41,20 @@ def test_use_value_defined_in_environment_file_in_database_yml
end
def
test_respect_environment_option
Dir
.
chdir
(
app_path
)
do
app_file
"config/database.yml"
,
<<-
YAML
default: &default
adapter: sqlite3
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
app_file
"config/database.yml"
,
<<-
YAML
default: &default
adapter: sqlite3
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
development:
<<: *default
database: db/development.sqlite3
production:
<<: *default
database: db/production.sqlite3
YAML
end
production:
<<: *default
database: db/production.sqlite3
YAML
master
,
slave
=
PTY
.
open
spawn_dbconsole
(
slave
,
"-e production"
)
...
...
railties/test/application/loading_test.rb
浏览文件 @
ac1ee519
...
...
@@ -300,7 +300,7 @@ def change
end
MIGRATION
Dir
.
chdir
(
app_path
)
{
`rake db:migrate`
}
rails
(
"db:migrate"
)
require
"
#{
rails_root
}
/config/environment"
get
"/title"
...
...
@@ -314,7 +314,7 @@ def change
end
MIGRATION
Dir
.
chdir
(
app_path
)
{
`rake db:migrate`
}
rails
(
"db:migrate"
)
get
"/body"
assert_equal
"BODY"
,
last_response
.
body
...
...
railties/test/application/rake/dbs_test.rb
浏览文件 @
ac1ee519
...
...
@@ -83,10 +83,8 @@ def with_bad_permissions
end
test
"db:drop failure because database does not exist"
do
Dir
.
chdir
(
app_path
)
do
output
=
rails
(
"db:drop:_unsafe"
,
"--trace"
)
assert_match
(
/does not exist/
,
output
)
end
output
=
rails
(
"db:drop:_unsafe"
,
"--trace"
)
assert_match
(
/does not exist/
,
output
)
end
test
"db:drop failure because bad permissions"
do
...
...
@@ -100,13 +98,11 @@ def with_bad_permissions
end
def
db_migrate_and_status
(
expected_database
)
Dir
.
chdir
(
app_path
)
do
rails
"generate"
,
"model"
,
"book"
,
"title:string"
rails
"db:migrate"
output
=
rails
(
"db:migrate:status"
)
assert_match
(
%r{database:
\s
+
\S
*
#{
Regexp
.
escape
(
expected_database
)
}
}
,
output
)
assert_match
(
/up\s+\d{14}\s+Create books/
,
output
)
end
rails
"generate"
,
"model"
,
"book"
,
"title:string"
rails
"db:migrate"
output
=
rails
(
"db:migrate:status"
)
assert_match
(
%r{database:
\s
+
\S
*
#{
Regexp
.
escape
(
expected_database
)
}
}
,
output
)
assert_match
(
/up\s+\d{14}\s+Create books/
,
output
)
end
test
"db:migrate and db:migrate:status without database_url"
do
...
...
@@ -161,12 +157,11 @@ def db_fixtures_load(expected_database)
test
"db:fixtures:load with namespaced fixture"
do
require
"
#{
app_path
}
/config/environment"
Dir
.
chdir
(
app_path
)
do
rails
"generate"
,
"model"
,
"admin::book"
,
"title:string"
rails
"db:migrate"
,
"db:fixtures:load"
require
"
#{
app_path
}
/app/models/admin/book"
assert_equal
2
,
Admin
::
Book
.
count
end
rails
"generate"
,
"model"
,
"admin::book"
,
"title:string"
rails
"db:migrate"
,
"db:fixtures:load"
require
"
#{
app_path
}
/app/models/admin/book"
assert_equal
2
,
Admin
::
Book
.
count
end
def
db_structure_dump_and_load
(
expected_database
)
...
...
@@ -205,56 +200,52 @@ def db_structure_dump_and_load(expected_database)
end
test
"db:schema:load and db:structure:load do not purge the existing database"
do
Dir
.
chdir
(
app_path
)
do
rails
"runner"
,
"ActiveRecord::Base.connection.create_table(:posts) {|t| t.string :title }"
rails
"runner"
,
"ActiveRecord::Base.connection.create_table(:posts) {|t| t.string :title }"
app_file
"db/schema.rb"
,
<<-
RUBY
ActiveRecord::Schema.define(version: 20140423102712) do
create_table(:comments) {}
end
RUBY
app_file
"db/schema.rb"
,
<<-
RUBY
ActiveRecord::Schema.define(version: 20140423102712) do
create_table(:comments) {}
end
RUBY
list_tables
=
lambda
{
rails
(
"runner"
,
"p ActiveRecord::Base.connection.tables"
).
strip
}
list_tables
=
lambda
{
rails
(
"runner"
,
"p ActiveRecord::Base.connection.tables"
).
strip
}
assert_equal
'["posts"]'
,
list_tables
[]
rails
"db:schema:load"
assert_equal
'["posts", "comments", "schema_migrations", "ar_internal_metadata"]'
,
list_tables
[]
assert_equal
'["posts"]'
,
list_tables
[]
rails
"db:schema:load"
assert_equal
'["posts", "comments", "schema_migrations", "ar_internal_metadata"]'
,
list_tables
[]
app_file
"db/structure.sql"
,
<<-
SQL
CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255));
SQL
app_file
"db/structure.sql"
,
<<-
SQL
CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255));
SQL
rails
"db:structure:load"
assert_equal
'["posts", "comments", "schema_migrations", "ar_internal_metadata", "users"]'
,
list_tables
[]
end
rails
"db:structure:load"
assert_equal
'["posts", "comments", "schema_migrations", "ar_internal_metadata", "users"]'
,
list_tables
[]
end
test
"db:schema:load with inflections"
do
Dir
.
chdir
(
app_path
)
do
app_file
"config/initializers/inflection.rb"
,
<<-
RUBY
ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'goose', 'geese'
end
RUBY
app_file
"config/initializers/primary_key_table_name.rb"
,
<<-
RUBY
ActiveRecord::Base.primary_key_prefix_type = :table_name
RUBY
app_file
"db/schema.rb"
,
<<-
RUBY
ActiveRecord::Schema.define(version: 20140423102712) do
create_table("goose".pluralize) do |t|
t.string :name
end
app_file
"config/initializers/inflection.rb"
,
<<-
RUBY
ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'goose', 'geese'
end
RUBY
app_file
"config/initializers/primary_key_table_name.rb"
,
<<-
RUBY
ActiveRecord::Base.primary_key_prefix_type = :table_name
RUBY
app_file
"db/schema.rb"
,
<<-
RUBY
ActiveRecord::Schema.define(version: 20140423102712) do
create_table("goose".pluralize) do |t|
t.string :name
end
RUBY
end
RUBY
rails
"db:schema:load"
rails
"db:schema:load"
tables
=
rails
(
"runner"
,
"p ActiveRecord::Base.connection.tables"
).
strip
assert_match
(
/"geese"/
,
tables
)
tables
=
rails
(
"runner"
,
"p ActiveRecord::Base.connection.tables"
).
strip
assert_match
(
/"geese"/
,
tables
)
columns
=
rails
(
"runner"
,
"p ActiveRecord::Base.connection.columns('geese').map(&:name)"
).
strip
assert_equal
columns
,
'["gooseid", "name"]'
end
columns
=
rails
(
"runner"
,
"p ActiveRecord::Base.connection.columns('geese').map(&:name)"
).
strip
assert_equal
columns
,
'["gooseid", "name"]'
end
test
"db:schema:load fails if schema.rb doesn't exist yet"
do
...
...
@@ -300,10 +291,8 @@ def db_test_load_structure
puts ActiveRecord::Base.connection_config[:database]
RUBY
Dir
.
chdir
(
app_path
)
do
database_path
=
rails
(
"db:setup"
)
assert_equal
"development.sqlite3"
,
File
.
basename
(
database_path
.
strip
)
end
database_path
=
rails
(
"db:setup"
)
assert_equal
"development.sqlite3"
,
File
.
basename
(
database_path
.
strip
)
ensure
ENV
[
"RAILS_ENV"
]
=
@old_rails_env
ENV
[
"RACK_ENV"
]
=
@old_rack_env
...
...
railties/test/application/rake/migrations_test.rb
浏览文件 @
ac1ee519
...
...
@@ -15,69 +15,63 @@ def teardown
end
test
"running migrations with given scope"
do
Dir
.
chdir
(
app_path
)
do
rails
"generate"
,
"model"
,
"user"
,
"username:string"
,
"password:string"
rails
"generate"
,
"model"
,
"user"
,
"username:string"
,
"password:string"
app_file
"db/migrate/01_a_migration.bukkits.rb"
,
<<-
MIGRATION
class AMigration < ActiveRecord::Migration::Current
end
MIGRATION
app_file
"db/migrate/01_a_migration.bukkits.rb"
,
<<-
MIGRATION
class AMigration < ActiveRecord::Migration::Current
end
MIGRATION
output
=
rails
(
"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
)
output
=
rails
(
"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
=
rails
(
"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
=
rails
(
"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
)
end
assert_match
(
/AMigration: reverted/
,
output
)
end
test
"migration with empty version"
do
Dir
.
chdir
(
app_path
)
do
output
=
rails
(
"db:migrate"
,
"VERSION="
,
allow_failure:
true
)
assert_match
(
/Empty VERSION provided/
,
output
)
output
=
rails
(
"db:migrate"
,
"VERSION="
,
allow_failure:
true
)
assert_match
(
/Empty VERSION provided/
,
output
)
output
=
rails
(
"db:migrate:redo"
,
"VERSION="
,
allow_failure:
true
)
assert_match
(
/Empty VERSION provided/
,
output
)
output
=
rails
(
"db:migrate:redo"
,
"VERSION="
,
allow_failure:
true
)
assert_match
(
/Empty VERSION provided/
,
output
)
output
=
rails
(
"db:migrate:up"
,
"VERSION="
,
allow_failure:
true
)
assert_match
(
/VERSION is required/
,
output
)
output
=
rails
(
"db:migrate:up"
,
"VERSION="
,
allow_failure:
true
)
assert_match
(
/VERSION is required/
,
output
)
output
=
rails
(
"db:migrate:up"
,
allow_failure:
true
)
assert_match
(
/VERSION is required/
,
output
)
output
=
rails
(
"db:migrate:up"
,
allow_failure:
true
)
assert_match
(
/VERSION is required/
,
output
)
output
=
rails
(
"db:migrate:down"
,
"VERSION="
,
allow_failure:
true
)
assert_match
(
/VERSION is required - To go down one migration, use db:rollback/
,
output
)
output
=
rails
(
"db:migrate:down"
,
"VERSION="
,
allow_failure:
true
)
assert_match
(
/VERSION is required - To go down one migration, use db:rollback/
,
output
)
output
=
rails
(
"db:migrate:down"
,
allow_failure:
true
)
assert_match
(
/VERSION is required - To go down one migration, use db:rollback/
,
output
)
end
output
=
rails
(
"db:migrate:down"
,
allow_failure:
true
)
assert_match
(
/VERSION is required - To go down one migration, use db:rollback/
,
output
)
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"
output
=
rails
(
"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
=
rails
(
"db:rollback"
,
"STEP=2"
)
assert_match
(
/drop_table\(:users\)/
,
output
)
assert_match
(
/CreateUsers: reverted/
,
output
)
assert_match
(
/remove_column\(:users, :email, :string\)/
,
output
)
assert_match
(
/AddEmailToUsers: reverted/
,
output
)
end
rails
"generate"
,
"model"
,
"user"
,
"username:string"
,
"password:string"
rails
"generate"
,
"migration"
,
"add_email_to_users"
,
"email:string"
output
=
rails
(
"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
=
rails
(
"db:rollback"
,
"STEP=2"
)
assert_match
(
/drop_table\(:users\)/
,
output
)
assert_match
(
/CreateUsers: reverted/
,
output
)
assert_match
(
/remove_column\(:users, :email, :string\)/
,
output
)
assert_match
(
/AddEmailToUsers: reverted/
,
output
)
end
test
"migration status when schema migrations table is not present"
do
...
...
@@ -86,93 +80,85 @@ class AMigration < ActiveRecord::Migration::Current
end
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"
rails
"db:migrate"
rails
"generate"
,
"model"
,
"user"
,
"username:string"
,
"password:string"
rails
"generate"
,
"migration"
,
"add_email_to_users"
,
"email:string"
rails
"db:migrate"
output
=
rails
(
"db:migrate:status"
)
output
=
rails
(
"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
)
rails
"db:rollback"
,
"STEP=1"
output
=
rails
(
"db:migrate:status"
)
rails
"db:rollback"
,
"STEP=1"
output
=
rails
(
"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
)
end
assert_match
(
/up\s+\d{14}\s+Create users/
,
output
)
assert_match
(
/down\s+\d{14}\s+Add email to users/
,
output
)
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"
rails
"db:migrate"
rails
"generate"
,
"model"
,
"user"
,
"username:string"
,
"password:string"
rails
"generate"
,
"migration"
,
"add_email_to_users"
,
"email:string"
rails
"db:migrate"
output
=
rails
(
"db:migrate:status"
)
output
=
rails
(
"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
)
rails
"db:rollback"
,
"STEP=1"
output
=
rails
(
"db:migrate:status"
)
rails
"db:rollback"
,
"STEP=1"
output
=
rails
(
"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
)
end
assert_match
(
/up\s+\d{3,}\s+Create users/
,
output
)
assert_match
(
/down\s+\d{3,}\s+Add email to users/
,
output
)
end
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"
rails
"db:migrate"
rails
"generate"
,
"model"
,
"user"
,
"username:string"
,
"password:string"
rails
"generate"
,
"migration"
,
"add_email_to_users"
,
"email:string"
rails
"db:migrate"
output
=
rails
(
"db:migrate:status"
)
output
=
rails
(
"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
)
rails
"db:rollback"
,
"STEP=2"
output
=
rails
(
"db:migrate:status"
)
rails
"db:rollback"
,
"STEP=2"
output
=
rails
(
"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
)
rails
"db:migrate:redo"
output
=
rails
(
"db:migrate:status"
)
rails
"db:migrate:redo"
output
=
rails
(
"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
)
end
assert_match
(
/up\s+\d{14}\s+Create users/
,
output
)
assert_match
(
/up\s+\d{14}\s+Add email to users/
,
output
)
end
test
"migration status after rollback and forward"
do
Dir
.
chdir
(
app_path
)
do
rails
"generate"
,
"model"
,
"user"
,
"username:string"
,
"password:string"
rails
"generate"
,
"migration"
,
"add_email_to_users"
,
"email:string"
rails
"db:migrate"
rails
"generate"
,
"model"
,
"user"
,
"username:string"
,
"password:string"
rails
"generate"
,
"migration"
,
"add_email_to_users"
,
"email:string"
rails
"db:migrate"
output
=
rails
(
"db:migrate:status"
)
output
=
rails
(
"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
)
rails
"db:rollback"
,
"STEP=2"
output
=
rails
(
"db:migrate:status"
)
rails
"db:rollback"
,
"STEP=2"
output
=
rails
(
"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
)
rails
"db:forward"
,
"STEP=2"
output
=
rails
(
"db:migrate:status"
)
rails
"db:forward"
,
"STEP=2"
output
=
rails
(
"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
)
end
assert_match
(
/up\s+\d{14}\s+Create users/
,
output
)
assert_match
(
/up\s+\d{14}\s+Add email to users/
,
output
)
end
test
"raise error on any move when current migration does not exist"
do
...
...
@@ -209,50 +195,45 @@ class AMigration < ActiveRecord::Migration::Current
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"
rails
"db:migrate"
rails
"generate"
,
"model"
,
"user"
,
"username:string"
,
"password:string"
rails
"generate"
,
"migration"
,
"add_email_to_users"
,
"email:string"
rails
"db:migrate"
output
=
rails
(
"db:migrate:status"
)
output
=
rails
(
"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
)
rails
"db:rollback"
,
"STEP=2"
output
=
rails
(
"db:migrate:status"
)
rails
"db:rollback"
,
"STEP=2"
output
=
rails
(
"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
)
rails
"db:migrate:redo"
output
=
rails
(
"db:migrate:status"
)
rails
"db:migrate:redo"
output
=
rails
(
"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
)
end
assert_match
(
/up\s+\d{3,}\s+Create users/
,
output
)
assert_match
(
/up\s+\d{3,}\s+Add email to users/
,
output
)
end
test
"running migrations with not timestamp head migration files"
do
Dir
.
chdir
(
app_path
)
do
app_file
"db/migrate/1_one_migration.rb"
,
<<-
MIGRATION
class OneMigration < ActiveRecord::Migration::Current
end
MIGRATION
app_file
"db/migrate/1_one
_migration.rb"
,
<<-
MIGRATION
class One
Migration < ActiveRecord::Migration::Current
end
MIGRATION
app_file
"db/migrate/02_two
_migration.rb"
,
<<-
MIGRATION
class Two
Migration < ActiveRecord::Migration::Current
end
MIGRATION
app_file
"db/migrate/02_two_migration.rb"
,
<<-
MIGRATION
class TwoMigration < ActiveRecord::Migration::Current
end
MIGRATION
rails
"db:migrate"
rails
"db:migrate"
output
=
rails
(
"db:migrate:status"
)
output
=
rails
(
"db:migrate:status"
)
assert_match
(
/up\s+001\s+One migration/
,
output
)
assert_match
(
/up\s+002\s+Two migration/
,
output
)
end
assert_match
(
/up\s+001\s+One migration/
,
output
)
assert_match
(
/up\s+002\s+Two migration/
,
output
)
end
test
"schema generation when dump_schema_after_migration is set"
do
...
...
railties/test/application/rake_test.rb
浏览文件 @
ac1ee519
...
...
@@ -40,7 +40,7 @@ def test_not_protected_when_previous_migration_was_not_production
with_rails_env
"test"
do
rails
"generate"
,
"model"
,
"product"
,
"name:string"
rails
"db:create"
,
"db:migrate"
output
=
Dir
.
chdir
(
app_path
)
{
rails
(
"db:test:prepare"
,
"test"
)
}
output
=
rails
(
"db:test:prepare"
,
"test"
)
refute_match
(
/ActiveRecord::ProtectedEnvironmentError/
,
output
)
end
...
...
@@ -101,6 +101,7 @@ def test_should_not_eager_load_model_for_rake
add_to_config
<<-
RUBY
rake_tasks do
task do_nothing: :environment do
puts 'There is nothing'
end
end
RUBY
...
...
@@ -113,10 +114,8 @@ def test_should_not_eager_load_model_for_rake
raise 'should not be pre-required for rake even eager_load=true'
RUBY
Dir
.
chdir
(
app_path
)
do
assert
system
(
"bin/rails do_nothing RAILS_ENV=production"
),
"should not be pre-required for rake even eager_load=true"
end
output
=
rails
(
"do_nothing"
,
"RAILS_ENV=production"
)
assert_match
"There is nothing"
,
output
end
def
test_code_statistics_sanity
...
...
@@ -294,9 +293,8 @@ def test_loading_only_yml_fixtures
def
test_scaffold_tests_pass_by_default
rails
"generate"
,
"scaffold"
,
"user"
,
"username:string"
,
"password:string"
output
=
Dir
.
chdir
(
app_path
)
do
`RAILS_ENV=test bin/rails db:migrate test`
end
with_rails_env
(
"test"
)
{
rails
(
"db:migrate"
)
}
output
=
rails
(
"test"
)
assert_match
(
/7 runs, 9 assertions, 0 failures, 0 errors/
,
output
)
assert_no_match
(
/Errors running/
,
output
)
...
...
@@ -313,9 +311,8 @@ class ApplicationController < ActionController::API
RUBY
rails
"generate"
,
"scaffold"
,
"user"
,
"username:string"
,
"password:string"
output
=
Dir
.
chdir
(
app_path
)
do
`RAILS_ENV=test bin/rails db:migrate test`
end
with_rails_env
(
"test"
)
{
rails
(
"db:migrate"
)
}
output
=
rails
(
"test"
)
assert_match
(
/5 runs, 7 assertions, 0 failures, 0 errors/
,
output
)
assert_no_match
(
/Errors running/
,
output
)
...
...
@@ -325,9 +322,8 @@ def test_scaffold_with_references_columns_tests_pass_by_default
rails
"generate"
,
"model"
,
"Product"
rails
"generate"
,
"model"
,
"Cart"
rails
"generate"
,
"scaffold"
,
"LineItems"
,
"product:references"
,
"cart:belongs_to"
output
=
Dir
.
chdir
(
app_path
)
do
`RAILS_ENV=test bin/rails db:migrate test`
end
with_rails_env
(
"test"
)
{
rails
(
"db:migrate"
)
}
output
=
rails
(
"test"
)
assert_match
(
/7 runs, 9 assertions, 0 failures, 0 errors/
,
output
)
assert_no_match
(
/Errors running/
,
output
)
...
...
@@ -337,9 +333,7 @@ def test_db_test_prepare_when_using_sql_format
add_to_config
"config.active_record.schema_format = :sql"
rails
"generate"
,
"scaffold"
,
"user"
,
"username:string"
rails
"db:migrate"
output
=
with_rails_env
(
"test"
)
do
rails
"db:test:prepare"
,
"--trace"
end
output
=
rails
(
"db:test:prepare"
,
"--trace"
)
assert_match
(
/Execute db:test:load_structure/
,
output
)
end
...
...
@@ -372,14 +366,12 @@ def test_rake_clear_schema_cache
end
def
test_copy_templates
Dir
.
chdir
(
app_path
)
do
rails
"app:templates:copy"
%w(controller mailer scaffold)
.
each
do
|
dir
|
assert
File
.
exist?
(
File
.
join
(
app_path
,
"lib"
,
"templates"
,
"erb"
,
dir
))
end
%w(controller helper scaffold_controller assets)
.
each
do
|
dir
|
assert
File
.
exist?
(
File
.
join
(
app_path
,
"lib"
,
"templates"
,
"rails"
,
dir
))
end
rails
"app:templates:copy"
%w(controller mailer scaffold)
.
each
do
|
dir
|
assert
File
.
exist?
(
File
.
join
(
app_path
,
"lib"
,
"templates"
,
"erb"
,
dir
))
end
%w(controller helper scaffold_controller assets)
.
each
do
|
dir
|
assert
File
.
exist?
(
File
.
join
(
app_path
,
"lib"
,
"templates"
,
"rails"
,
dir
))
end
end
...
...
railties/test/application/server_test.rb
浏览文件 @
ac1ee519
...
...
@@ -42,7 +42,7 @@ def teardown
pid
=
Process
.
spawn
(
"
#{
app_path
}
/bin/rails server -P tmp/dummy.pid"
,
in:
slave
,
out:
slave
,
err:
slave
)
assert_output
(
"Listening"
,
master
)
Dir
.
chdir
(
app_path
)
{
system
(
"bin/rails restart"
)
}
rails
(
"restart"
)
assert_output
(
"Restarting"
,
master
)
assert_output
(
"Inherited"
,
master
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录