Skip to content

Commit

Permalink
Fix automated ActiveRecord database creation during tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mrrooijen committed Nov 15, 2024
1 parent d229a66 commit bfeef2c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 30 deletions.
11 changes: 4 additions & 7 deletions test/hirefire/macro/test_delayed_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 4 additions & 7 deletions test/hirefire/macro/test_good_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 5 additions & 9 deletions test/hirefire/macro/test_que.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 4 additions & 7 deletions test/hirefire/macro/test_queue_classic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit bfeef2c

Please sign in to comment.