1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Load test schema even if there are no migrations

Fixes #17170
This commit is contained in:
Sean Griffin 2014-10-31 15:20:44 -06:00
parent 487145f871
commit 61bacd6ef9
2 changed files with 18 additions and 1 deletions

View file

@ -394,7 +394,7 @@ module ActiveRecord
end end
def load_schema_if_pending! def load_schema_if_pending!
if ActiveRecord::Migrator.needs_migration? if ActiveRecord::Migrator.needs_migration? || !ActiveRecord::Migrator.any_migrations?
ActiveRecord::Tasks::DatabaseTasks.load_schema_current ActiveRecord::Tasks::DatabaseTasks.load_schema_current
check_pending! check_pending!
end end
@ -848,6 +848,10 @@ module ActiveRecord
(migrations(migrations_paths).collect(&:version) - get_all_versions(connection)).size > 0 (migrations(migrations_paths).collect(&:version) - get_all_versions(connection)).size > 0
end end
def any_migrations?
migrations(migrations_paths).any?
end
def last_version def last_version
last_migration.version last_migration.version
end end

View file

@ -100,6 +100,19 @@ class MigrationTest < ActiveRecord::TestCase
ActiveRecord::Migrator.migrations_paths = old_path ActiveRecord::Migrator.migrations_paths = old_path
end end
def test_any_migrations
old_path = ActiveRecord::Migrator.migrations_paths
ActiveRecord::Migrator.migrations_paths = MIGRATIONS_ROOT + "/valid"
assert ActiveRecord::Migrator.any_migrations?
ActiveRecord::Migrator.migrations_paths = MIGRATIONS_ROOT + "/empty"
assert_not ActiveRecord::Migrator.any_migrations?
ensure
ActiveRecord::Migrator.migrations_paths = old_path
end
def test_migration_version def test_migration_version
ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT + "/version_check", 20131219224947) ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT + "/version_check", 20131219224947)
end end