aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/migration_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test/cases/migration_test.rb')
-rw-r--r--activerecord/test/cases/migration_test.rb43
1 files changed, 32 insertions, 11 deletions
diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb
index ebe563059d..75c939f24f 100644
--- a/activerecord/test/cases/migration_test.rb
+++ b/activerecord/test/cases/migration_test.rb
@@ -757,9 +757,9 @@ if ActiveRecord::Base.connection.supports_migrations?
def test_migrator_one_down
ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid")
-
+
ActiveRecord::Migrator.down(MIGRATIONS_ROOT + "/valid", 1)
-
+
Person.reset_column_information
assert Person.column_methods_hash.include?(:last_name)
assert !Reminder.table_exists?
@@ -805,6 +805,33 @@ if ActiveRecord::Base.connection.supports_migrations?
assert Reminder.create("content" => "hello world", "remind_at" => Time.now)
assert_equal "hello world", Reminder.find(:first).content
end
+
+ def test_migrator_rollback
+ ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid")
+ assert_equal(3, ActiveRecord::Migrator.current_version)
+
+ ActiveRecord::Migrator.rollback(MIGRATIONS_ROOT + "/valid")
+ assert_equal(2, ActiveRecord::Migrator.current_version)
+
+ ActiveRecord::Migrator.rollback(MIGRATIONS_ROOT + "/valid")
+ assert_equal(1, ActiveRecord::Migrator.current_version)
+
+ ActiveRecord::Migrator.rollback(MIGRATIONS_ROOT + "/valid")
+ assert_equal(0, ActiveRecord::Migrator.current_version)
+
+ ActiveRecord::Migrator.rollback(MIGRATIONS_ROOT + "/valid")
+ assert_equal(0, ActiveRecord::Migrator.current_version)
+ end
+
+ def test_migrator_run
+ assert_equal(0, ActiveRecord::Migrator.current_version)
+ ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT + "/valid", 3)
+ assert_equal(0, ActiveRecord::Migrator.current_version)
+
+ assert_equal(0, ActiveRecord::Migrator.current_version)
+ ActiveRecord::Migrator.run(:down, MIGRATIONS_ROOT + "/valid", 3)
+ assert_equal(0, ActiveRecord::Migrator.current_version)
+ end
def test_schema_info_table_name
ActiveRecord::Base.table_name_prefix = "prefix_"
@@ -892,15 +919,9 @@ if ActiveRecord::Base.connection.supports_migrations?
end
def test_migrator_with_missing_version_numbers
- ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/missing", 500)
- assert !Person.column_methods_hash.include?(:middle_name)
- assert_equal 4, ActiveRecord::Migrator.current_version
-
- ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/missing", 2)
- Person.reset_column_information
- assert !Reminder.table_exists?
- assert Person.column_methods_hash.include?(:last_name)
- assert_equal 2, ActiveRecord::Migrator.current_version
+ assert_raise(ActiveRecord::UnknownMigrationVersionError) do
+ ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/missing", 500)
+ end
end
def test_create_table_with_custom_sequence_name