diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2017-08-17 14:54:54 +0300 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2017-08-17 14:54:54 +0300 |
commit | c3e0f31dfbd1ab3f17d9acaf9cba47cfbb280c1c (patch) | |
tree | 52c70f6569c01431956b875e212983a3d5a9cd6a /spec/support | |
parent | fe0ffcc78941bf9de98e3698e743c3cbb9846b6a (diff) | |
parent | 3a29646d73b7afdf2a2356c7e92ed397cc80009f (diff) |
Merge branch 'backstage/gb/migrations-tests-schema-version' into 'master'
Improve migrations / background migrations testing strategy
Closes #36303
See merge request !13589
Diffstat (limited to 'spec/support')
-rw-r--r-- | spec/support/db_cleaner.rb | 2 | ||||
-rw-r--r-- | spec/support/migrations_helpers.rb | 29 |
2 files changed, 30 insertions, 1 deletions
diff --git a/spec/support/db_cleaner.rb b/spec/support/db_cleaner.rb index 7f5769209bb..b0f520d08e8 100644 --- a/spec/support/db_cleaner.rb +++ b/spec/support/db_cleaner.rb @@ -20,7 +20,7 @@ RSpec.configure do |config| end config.before(:each, :migration) do - DatabaseCleaner.strategy = :truncation + DatabaseCleaner.strategy = :truncation, { cache_tables: false } end config.before(:each) do diff --git a/spec/support/migrations_helpers.rb b/spec/support/migrations_helpers.rb index aabdad13047..255b3d96a62 100644 --- a/spec/support/migrations_helpers.rb +++ b/spec/support/migrations_helpers.rb @@ -31,6 +31,35 @@ module MigrationsHelpers end end + def migration_schema_version + self.class.metadata[:schema] || previous_migration.version + end + + def schema_migrate_down! + disable_migrations_output do + ActiveRecord::Migrator.migrate(migrations_paths, + migration_schema_version) + end + + reset_column_in_migration_models + end + + def schema_migrate_up! + disable_migrations_output do + ActiveRecord::Migrator.migrate(migrations_paths) + end + + reset_column_in_migration_models + end + + def disable_migrations_output + ActiveRecord::Migration.verbose = false + + yield + ensure + ActiveRecord::Migration.verbose = true + end + def migrate! ActiveRecord::Migrator.up(migrations_paths) do |migration| migration.name == described_class.name |