mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Moves migrations tests from railties/test/application/rake_test.rb to railties/test/application/rake/migrations_test.rb
This commit is contained in:
parent
c45f744bb0
commit
c6e6ce437c
2 changed files with 85 additions and 68 deletions
85
railties/test/application/rake/migrations_test.rb
Normal file
85
railties/test/application/rake/migrations_test.rb
Normal file
|
@ -0,0 +1,85 @@
|
|||
require "isolation/abstract_unit"
|
||||
|
||||
module ApplicationTests
|
||||
module RakeTests
|
||||
class RakeMigrationsTest < Test::Unit::TestCase
|
||||
def setup
|
||||
build_app
|
||||
boot_rails
|
||||
FileUtils.rm_rf("#{app_path}/config/environments")
|
||||
end
|
||||
|
||||
def teardown
|
||||
teardown_app
|
||||
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`
|
||||
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
|
||||
output = Dir.chdir(app_path){ `rake db:migrate:status` }
|
||||
assert_equal "Schema migrations table does not exist yet.\n", output
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
end
|
||||
end
|
|
@ -108,74 +108,6 @@ module ApplicationTests
|
|||
assert_match "Sample log message", output
|
||||
end
|
||||
|
||||
def test_model_and_migration_generator_with_change_syntax
|
||||
Dir.chdir(app_path) do
|
||||
`rails generate model user username:string password:string`
|
||||
`rails generate migration add_email_to_users email:string`
|
||||
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
|
||||
|
||||
def test_migration_status_when_schema_migrations_table_is_not_present
|
||||
output = Dir.chdir(app_path){ `rake db:migrate:status` }
|
||||
assert_equal "Schema migrations table does not exist yet.\n", output
|
||||
end
|
||||
|
||||
def test_migration_status
|
||||
Dir.chdir(app_path) do
|
||||
`rails generate model user username:string password:string`
|
||||
`rails generate migration add_email_to_users email:string`
|
||||
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
|
||||
|
||||
def test_migration_status_after_rollback_and_redo
|
||||
Dir.chdir(app_path) do
|
||||
`rails generate model user username:string password:string`
|
||||
`rails generate migration add_email_to_users email:string`
|
||||
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
|
||||
|
||||
def test_loading_specific_fixtures
|
||||
Dir.chdir(app_path) do
|
||||
`rails generate model user username:string password:string`
|
||||
|
|
Loading…
Reference in a new issue