Skip to content

Commit b1e3fe4

Browse files
committed
fix
1 parent 6ecd0c3 commit b1e3fe4

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

spec/spec_helper.rb

+6-3
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,19 @@ def sqlite?
9898

9999
# Require our gem
100100
require 'closure_tree'
101+
102+
ActiveRecord::Tasks::DatabaseTasks.drop_current(:primary)
101103
begin
102104
ActiveRecord::Base.establish_connection(:primary)
103105
rescue
104-
ActiveRecord::Tasks::DatabaseTasks.create_current('primary')
106+
ActiveRecord::Tasks::DatabaseTasks.create_current(:primary)
105107
end
106-
108+
ActiveRecord::Tasks::DatabaseTasks.drop_current(:secondary)
107109
begin
108110
ActiveRecord::Base.establish_connection(:secondary)
111+
ActiveRecord::Base.database_exists?(:secondary)
109112
rescue
110-
ActiveRecord::Tasks::DatabaseTasks.create_current('secondary')
113+
ActiveRecord::Tasks::DatabaseTasks.create_current(:secondary)
111114
end
112115

113116
# Load test helpers

spec/support/schema.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
class ApplicationRecord < ActiveRecord::Base
44
self.abstract_class = true
5+
6+
connects_to database: { writing: :primary, reading: :primary }
57
end
68

79
class SecondDatabaseRecord < ActiveRecord::Base
810
self.abstract_class = true
911

10-
establish_connection :secondary
12+
connects_to database: { writing: :secondary, reading: :secondary }
1113
end
1214

1315
ActiveRecord::Schema.define(version: 0) do
@@ -151,6 +153,7 @@ class SecondDatabaseRecord < ActiveRecord::Base
151153
add_foreign_key(:tag_hierarchies, :tags, column: 'descendant_id', on_delete: :cascade)
152154
end
153155

156+
SecondDatabaseRecord.establish_connection
154157
SecondDatabaseRecord.connection_pool.with_connection do |connection|
155158
ActiveRecord::Schema.define(version: 0) do
156159
connection.create_table 'menu_items', force: :cascade do |t|

0 commit comments

Comments
 (0)