diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index aabdd6f..1c02f25 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -98,17 +98,11 @@ def sqlite? # Require our gem require 'closure_tree' -begin - ActiveRecord::Base.establish_connection(:primary) -rescue - ActiveRecord::Tasks::DatabaseTasks.create_current('primary') -end -begin - ActiveRecord::Base.establish_connection(:secondary) -rescue - ActiveRecord::Tasks::DatabaseTasks.create_current('secondary') -end +ActiveRecord::Tasks::DatabaseTasks.drop_current(:primary) +ActiveRecord::Tasks::DatabaseTasks.create_current(:primary) +ActiveRecord::Tasks::DatabaseTasks.drop_current(:secondary) +ActiveRecord::Tasks::DatabaseTasks.create_current(:secondary) # Load test helpers require_relative 'support/schema' diff --git a/spec/support/schema.rb b/spec/support/schema.rb index 0626605..665f46f 100644 --- a/spec/support/schema.rb +++ b/spec/support/schema.rb @@ -2,12 +2,14 @@ class ApplicationRecord < ActiveRecord::Base self.abstract_class = true + + connects_to database: { writing: :primary, reading: :primary } end class SecondDatabaseRecord < ActiveRecord::Base self.abstract_class = true - establish_connection :secondary + connects_to database: { writing: :secondary, reading: :secondary } end ActiveRecord::Schema.define(version: 0) do @@ -151,6 +153,7 @@ class SecondDatabaseRecord < ActiveRecord::Base add_foreign_key(:tag_hierarchies, :tags, column: 'descendant_id', on_delete: :cascade) end +SecondDatabaseRecord.establish_connection SecondDatabaseRecord.connection_pool.with_connection do |connection| ActiveRecord::Schema.define(version: 0) do connection.create_table 'menu_items', force: :cascade do |t| diff --git a/test/test_helper.rb b/test/test_helper.rb index 8a870a6..f1c547a 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -67,17 +67,10 @@ class Spec Thread.abort_on_exception = true require 'closure_tree' -begin - ActiveRecord::Base.establish_connection(:primary) -rescue - ActiveRecord::Tasks::DatabaseTasks.create_current('primary') -end - -begin - ActiveRecord::Base.establish_connection(:secondary) -rescue - ActiveRecord::Tasks::DatabaseTasks.create_current('secondary') -end +ActiveRecord::Tasks::DatabaseTasks.drop_current(:primary) +ActiveRecord::Tasks::DatabaseTasks.create_current(:primary) +ActiveRecord::Tasks::DatabaseTasks.drop_current(:secondary) +ActiveRecord::Tasks::DatabaseTasks.create_current(:secondary) require_relative '../spec/support/schema' require_relative '../spec/support/models'