mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Use one system call whenever possible, group rake and Dir.chdir calls
This commit is contained in:
parent
8a714c4d80
commit
73e8e70066
4 changed files with 117 additions and 125 deletions
|
@ -196,9 +196,8 @@ module ApplicationTests
|
||||||
|
|
||||||
test "use schema cache dump" do
|
test "use schema cache dump" do
|
||||||
Dir.chdir(app_path) do
|
Dir.chdir(app_path) do
|
||||||
`rails generate model post title:string`
|
`rails generate model post title:string;
|
||||||
`bundle exec rake db:migrate`
|
bundle exec rake db:migrate db:schema:cache:dump`
|
||||||
`bundle exec rake db:schema:cache:dump`
|
|
||||||
end
|
end
|
||||||
require "#{app_path}/config/environment"
|
require "#{app_path}/config/environment"
|
||||||
ActiveRecord::Base.connection.drop_table("posts") # force drop posts table for test.
|
ActiveRecord::Base.connection.drop_table("posts") # force drop posts table for test.
|
||||||
|
@ -207,17 +206,13 @@ module ApplicationTests
|
||||||
|
|
||||||
test "expire schema cache dump" do
|
test "expire schema cache dump" do
|
||||||
Dir.chdir(app_path) do
|
Dir.chdir(app_path) do
|
||||||
`rails generate model post title:string`
|
`rails generate model post title:string;
|
||||||
`bundle exec rake db:migrate`
|
bundle exec rake db:migrate db:schema:cache:dump db:rollback`
|
||||||
`bundle exec rake db:schema:cache:dump`
|
|
||||||
|
|
||||||
`bundle exec rake db:rollback`
|
|
||||||
end
|
end
|
||||||
silence_warnings {
|
silence_warnings {
|
||||||
require "#{app_path}/config/environment"
|
require "#{app_path}/config/environment"
|
||||||
assert !ActiveRecord::Base.connection.schema_cache.tables["posts"]
|
assert !ActiveRecord::Base.connection.schema_cache.tables["posts"]
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,44 +16,45 @@ module ApplicationTests
|
||||||
test 'running migrations with given scope' do
|
test 'running migrations with given scope' do
|
||||||
Dir.chdir(app_path) 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
|
||||||
|
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)
|
||||||
|
|
||||||
|
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)
|
||||||
end
|
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)
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
assert_match(/AMigration: reverted/, output)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'model and migration generator with change syntax' do
|
test 'model and migration generator with change syntax' do
|
||||||
Dir.chdir(app_path) do
|
Dir.chdir(app_path) do
|
||||||
`rails generate model user username:string password:string`
|
`rails generate model user username:string password:string;
|
||||||
`rails generate migration add_email_to_users email: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
|
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
|
end
|
||||||
|
|
||||||
test 'migration status when schema migrations table is not present' do
|
test 'migration status when schema migrations table is not present' do
|
||||||
|
@ -63,94 +64,94 @@ module ApplicationTests
|
||||||
|
|
||||||
test 'test migration status' do
|
test 'test migration status' do
|
||||||
Dir.chdir(app_path) do
|
Dir.chdir(app_path) do
|
||||||
`rails generate model user username:string password:string`
|
`rails generate model user username:string password:string;
|
||||||
`rails generate migration add_email_to_users email:string`
|
rails generate migration add_email_to_users email:string;
|
||||||
|
rake db:migrate`
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
`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)
|
||||||
end
|
end
|
||||||
|
|
||||||
Dir.chdir(app_path) { `rake db:migrate` }
|
|
||||||
output = Dir.chdir(app_path) { `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)
|
|
||||||
|
|
||||||
Dir.chdir(app_path) { `rake db:rollback STEP=1` }
|
|
||||||
output = Dir.chdir(app_path) { `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)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'migration status without timestamps' do
|
test 'migration status without timestamps' do
|
||||||
add_to_config('config.active_record.timestamped_migrations = false')
|
add_to_config('config.active_record.timestamped_migrations = false')
|
||||||
|
|
||||||
Dir.chdir(app_path) do
|
Dir.chdir(app_path) do
|
||||||
`rails generate model user username:string password:string`
|
`rails generate model user username:string password:string;
|
||||||
`rails generate migration add_email_to_users email:string`
|
rails generate migration add_email_to_users email:string;
|
||||||
|
rake db:migrate`
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
`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)
|
||||||
end
|
end
|
||||||
|
|
||||||
Dir.chdir(app_path) { `rake db:migrate` }
|
|
||||||
output = Dir.chdir(app_path) { `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)
|
|
||||||
|
|
||||||
Dir.chdir(app_path) { `rake db:rollback STEP=1` }
|
|
||||||
output = Dir.chdir(app_path) { `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)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'test migration status after rollback and redo' do
|
test 'test migration status after rollback and redo' do
|
||||||
Dir.chdir(app_path) do
|
Dir.chdir(app_path) do
|
||||||
`rails generate model user username:string password:string`
|
`rails generate model user username:string password:string;
|
||||||
`rails generate migration add_email_to_users email:string`
|
rails generate migration add_email_to_users email:string;
|
||||||
|
rake db:migrate`
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
`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)
|
||||||
|
|
||||||
|
`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)
|
||||||
end
|
end
|
||||||
|
|
||||||
Dir.chdir(app_path) { `rake db:migrate` }
|
|
||||||
output = Dir.chdir(app_path) { `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)
|
|
||||||
|
|
||||||
Dir.chdir(app_path) { `rake db:rollback STEP=2` }
|
|
||||||
output = Dir.chdir(app_path) { `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)
|
|
||||||
|
|
||||||
Dir.chdir(app_path) { `rake db:migrate:redo` }
|
|
||||||
output = Dir.chdir(app_path) { `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)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'migration status after rollback and redo without timestamps' do
|
test 'migration status after rollback and redo without timestamps' do
|
||||||
add_to_config('config.active_record.timestamped_migrations = false')
|
add_to_config('config.active_record.timestamped_migrations = false')
|
||||||
|
|
||||||
Dir.chdir(app_path) do
|
Dir.chdir(app_path) do
|
||||||
`rails generate model user username:string password:string`
|
`rails generate model user username:string password:string;
|
||||||
`rails generate migration add_email_to_users email:string`
|
rails generate migration add_email_to_users email:string;
|
||||||
|
rake db:migrate`
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
`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)
|
||||||
|
|
||||||
|
`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)
|
||||||
end
|
end
|
||||||
|
|
||||||
Dir.chdir(app_path) { `rake db:migrate` }
|
|
||||||
output = Dir.chdir(app_path) { `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)
|
|
||||||
|
|
||||||
Dir.chdir(app_path) { `rake db:rollback STEP=2` }
|
|
||||||
output = Dir.chdir(app_path) { `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)
|
|
||||||
|
|
||||||
Dir.chdir(app_path) { `rake db:migrate:redo` }
|
|
||||||
output = Dir.chdir(app_path) { `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)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@ require "isolation/abstract_unit"
|
||||||
module ApplicationTests
|
module ApplicationTests
|
||||||
module RakeTests
|
module RakeTests
|
||||||
class RakeNotesTest < ActiveSupport::TestCase
|
class RakeNotesTest < ActiveSupport::TestCase
|
||||||
def setup
|
def setup
|
||||||
build_app
|
build_app
|
||||||
require "rails/all"
|
require "rails/all"
|
||||||
end
|
end
|
||||||
|
@ -13,7 +13,6 @@ module ApplicationTests
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'notes' do
|
test 'notes' do
|
||||||
|
|
||||||
app_file "app/views/home/index.html.erb", "<% # TODO: note in erb %>"
|
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.haml", "-# TODO: note in haml"
|
||||||
app_file "app/views/home/index.html.slim", "/ TODO: note in slim"
|
app_file "app/views/home/index.html.slim", "/ TODO: note in slim"
|
||||||
|
|
|
@ -107,9 +107,9 @@ module ApplicationTests
|
||||||
|
|
||||||
def test_loading_specific_fixtures
|
def test_loading_specific_fixtures
|
||||||
Dir.chdir(app_path) do
|
Dir.chdir(app_path) do
|
||||||
`rails generate model user username:string password:string`
|
`rails generate model user username:string password:string;
|
||||||
`rails generate model product name:string`
|
rails generate model product name:string;
|
||||||
`rake db:migrate`
|
rake db:migrate`
|
||||||
end
|
end
|
||||||
|
|
||||||
require "#{rails_root}/config/environment"
|
require "#{rails_root}/config/environment"
|
||||||
|
@ -124,8 +124,8 @@ module ApplicationTests
|
||||||
|
|
||||||
def test_scaffold_tests_pass_by_default
|
def test_scaffold_tests_pass_by_default
|
||||||
content = Dir.chdir(app_path) do
|
content = Dir.chdir(app_path) do
|
||||||
`rails generate scaffold user username:string password:string`
|
`rails generate scaffold user username:string password:string;
|
||||||
`bundle exec rake db:migrate db:test:clone test`
|
bundle exec rake db:migrate db:test:clone test`
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_match(/\d+ tests, \d+ assertions, 0 failures, 0 errors/, content)
|
assert_match(/\d+ tests, \d+ assertions, 0 failures, 0 errors/, content)
|
||||||
|
@ -133,29 +133,26 @@ module ApplicationTests
|
||||||
|
|
||||||
def test_rake_dump_structure_should_respect_db_structure_env_variable
|
def test_rake_dump_structure_should_respect_db_structure_env_variable
|
||||||
Dir.chdir(app_path) do
|
Dir.chdir(app_path) do
|
||||||
`bundle exec rake db:migrate` # ensure we have a schema_migrations table to dump
|
# ensure we have a schema_migrations table to dump
|
||||||
`bundle exec rake db:structure:dump DB_STRUCTURE=db/my_structure.sql`
|
`bundle exec rake db:migrate db:structure:dump DB_STRUCTURE=db/my_structure.sql`
|
||||||
end
|
end
|
||||||
assert File.exists?(File.join(app_path, 'db', 'my_structure.sql'))
|
assert File.exists?(File.join(app_path, 'db', 'my_structure.sql'))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_rake_dump_schema_cache
|
def test_rake_dump_schema_cache
|
||||||
Dir.chdir(app_path) do
|
Dir.chdir(app_path) do
|
||||||
`rails generate model post title:string`
|
`rails generate model post title:string;
|
||||||
`rails generate model product name:string`
|
rails generate model product name:string;
|
||||||
`bundle exec rake db:migrate`
|
bundle exec rake db:migrate db:schema:cache:dump`
|
||||||
`bundle exec rake db:schema:cache:dump`
|
|
||||||
end
|
end
|
||||||
assert File.exists?(File.join(app_path, 'db', 'schema_cache.dump'))
|
assert File.exists?(File.join(app_path, 'db', 'schema_cache.dump'))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_rake_clear_schema_cache
|
def test_rake_clear_schema_cache
|
||||||
Dir.chdir(app_path) do
|
Dir.chdir(app_path) do
|
||||||
`bundle exec rake db:schema:cache:dump`
|
`bundle exec rake db:schema:cache:dump db:schema:cache:clear`
|
||||||
`bundle exec rake db:schema:cache:clear`
|
|
||||||
end
|
end
|
||||||
assert !File.exists?(File.join(app_path, 'db', 'schema_cache.dump'))
|
assert !File.exists?(File.join(app_path, 'db', 'schema_cache.dump'))
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue