From b1e3fe406b7e2bb34f404e7ba17f8b607436258f Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Fri, 19 Jan 2024 00:18:39 +0100 Subject: [PATCH] fix --- spec/spec_helper.rb | 9 ++++++--- spec/support/schema.rb | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index aabdd6f..e069508 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -98,16 +98,19 @@ def sqlite? # Require our gem require 'closure_tree' + +ActiveRecord::Tasks::DatabaseTasks.drop_current(:primary) begin ActiveRecord::Base.establish_connection(:primary) rescue - ActiveRecord::Tasks::DatabaseTasks.create_current('primary') + ActiveRecord::Tasks::DatabaseTasks.create_current(:primary) end - +ActiveRecord::Tasks::DatabaseTasks.drop_current(:secondary) begin ActiveRecord::Base.establish_connection(:secondary) + ActiveRecord::Base.database_exists?(:secondary) rescue - ActiveRecord::Tasks::DatabaseTasks.create_current('secondary') + ActiveRecord::Tasks::DatabaseTasks.create_current(:secondary) end # Load test helpers 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|