From bfeef2c1e3eff596409cbd96d826f89bd8f3c934 Mon Sep 17 00:00:00 2001 From: Michael van Rooijen Date: Fri, 15 Nov 2024 14:35:22 +0100 Subject: [PATCH] Fix automated ActiveRecord database creation during tests --- test/hirefire/macro/test_delayed_job.rb | 11 ++++------- test/hirefire/macro/test_good_job.rb | 11 ++++------- test/hirefire/macro/test_que.rb | 14 +++++--------- test/hirefire/macro/test_queue_classic.rb | 11 ++++------- 4 files changed, 17 insertions(+), 30 deletions(-) diff --git a/test/hirefire/macro/test_delayed_job.rb b/test/hirefire/macro/test_delayed_job.rb index 07b4698..393614e 100644 --- a/test/hirefire/macro/test_delayed_job.rb +++ b/test/hirefire/macro/test_delayed_job.rb @@ -86,18 +86,15 @@ def test_deprecated_queue_method def prepare_active_record_database db_config = Rails.configuration.database_configuration[Rails.env] - ActiveRecord::Base.establish_connection(db_config) - begin - ActiveRecord::Base.connection + ActiveRecord::Base.establish_connection(db_config) + ActiveRecord::Migration.verbose = false + ActiveRecord::MigrationContext.new(Rails.root.join("db/migrate").to_s).migrate rescue ActiveRecord::NoDatabaseError ActiveRecord::Tasks::DatabaseTasks.create(db_config) - ActiveRecord::Base.establish_connection(db_config) + retry end - ActiveRecord::Migration.verbose = false - ActiveRecord::MigrationContext.new(Rails.root.join("db/migrate").to_s).migrate - Delayed::Job.delete_all end diff --git a/test/hirefire/macro/test_good_job.rb b/test/hirefire/macro/test_good_job.rb index 2c618a5..9f16355 100644 --- a/test/hirefire/macro/test_good_job.rb +++ b/test/hirefire/macro/test_good_job.rb @@ -76,18 +76,15 @@ def test_deprecated_queue_method def prepare_database db_config = Rails.configuration.database_configuration[Rails.env] - ActiveRecord::Base.establish_connection(db_config) - begin - ActiveRecord::Base.connection + ActiveRecord::Base.establish_connection(db_config) + ActiveRecord::Migration.verbose = false + ActiveRecord::MigrationContext.new(Rails.root.join("db/migrate").to_s).migrate rescue ActiveRecord::NoDatabaseError ActiveRecord::Tasks::DatabaseTasks.create(db_config) - ActiveRecord::Base.establish_connection(db_config) + retry end - ActiveRecord::Migration.verbose = false - ActiveRecord::MigrationContext.new(Rails.root.join("db/migrate").to_s).migrate - good_job_class.delete_all end end diff --git a/test/hirefire/macro/test_que.rb b/test/hirefire/macro/test_que.rb index 5cdd8a0..d771d64 100644 --- a/test/hirefire/macro/test_que.rb +++ b/test/hirefire/macro/test_que.rb @@ -115,20 +115,16 @@ def enqueue(*args, job_options: {}, **options) def prepare_database db_config = Rails.configuration.database_configuration[Rails.env] - ActiveRecord::Base.establish_connection(db_config) - begin - ActiveRecord::Base.connection + ActiveRecord::Base.establish_connection(db_config) + Que.connection = ::ActiveRecord + ActiveRecord::Migration.verbose = false + ActiveRecord::MigrationContext.new(Rails.root.join("db/migrate").to_s).migrate rescue ActiveRecord::NoDatabaseError ActiveRecord::Tasks::DatabaseTasks.create(db_config) - ActiveRecord::Base.establish_connection(db_config) + retry end - Que.connection = ::ActiveRecord - - ActiveRecord::Migration.verbose = false - ActiveRecord::MigrationContext.new(Rails.root.join("db/migrate").to_s).migrate - Que.execute("DELETE FROM que_jobs") end end diff --git a/test/hirefire/macro/test_queue_classic.rb b/test/hirefire/macro/test_queue_classic.rb index 53ece4a..8bf4300 100644 --- a/test/hirefire/macro/test_queue_classic.rb +++ b/test/hirefire/macro/test_queue_classic.rb @@ -60,18 +60,15 @@ def test_deprecated_queue_method def prepare_database db_config = Rails.configuration.database_configuration[Rails.env] - ActiveRecord::Base.establish_connection(db_config) - begin - ActiveRecord::Base.connection + ActiveRecord::Base.establish_connection(db_config) + ActiveRecord::Migration.verbose = false + ActiveRecord::MigrationContext.new(Rails.root.join("db/migrate").to_s).migrate rescue ActiveRecord::NoDatabaseError ActiveRecord::Tasks::DatabaseTasks.create(db_config) - ActiveRecord::Base.establish_connection(db_config) + retry end - ActiveRecord::Migration.verbose = false - ActiveRecord::MigrationContext.new(Rails.root.join("db/migrate").to_s).migrate - QC::Queue.new("default").conn_adapter.execute("DELETE FROM #{::QC.table_name}") end end