Skip to content

Commit 6ecd0c3

Browse files
committed
remove debug
1 parent 1837fd0 commit 6ecd0c3

File tree

8 files changed

+75
-43
lines changed

8 files changed

+75
-43
lines changed

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ jobs:
5050
- activerecord_6.1
5151
- activerecord_edge
5252
adapter:
53-
- '' # SQLite3
53+
- sqlite3:///tmp/closure_tree_test
5454
- mysql2://root:root@0/closure_tree_test
55-
- postgres://closure_tree:closure_tree@0/closure_tree_test
55+
- postgres://postgres:postgres@0/closure_tree_test
5656
exclude:
5757
- ruby: '3.0'
5858
rails: activerecord_edge

.github/workflows/ci_jruby.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ jobs:
4343
- activerecord_7.0
4444
- activerecord_6.1
4545
adapter:
46-
- '' # SQLite3
46+
- sqlite3:///tmp/closure_tree_test
4747
- mysql2://root:root@0/closure_tree_test
48-
- postgres://closure_tree:closure_tree@0/closure_tree_test
48+
- postgres://postgres:postgres@0/closure_tree_test
4949
steps:
5050
- name: Checkout
5151
uses: actions/checkout@v4

.github/workflows/ci_truffleruby.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ jobs:
4545
- activerecord_7.0
4646
- activerecord_6.1
4747
adapter:
48-
- '' # SQLite3
48+
- sqlite3:///tmp/closure_tree_test
4949
- mysql2://root:root@0/closure_tree_test
50-
- postgres://closure_tree:closure_tree@0/closure_tree_test
50+
- postgres://postgres:postgres@0/closure_tree_test
5151

5252
steps:
5353
- name: Checkout

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ tmp/
1414
.ruby-*
1515
*.iml
1616
coverage/
17+
.env

spec/spec_helper.rb

+33-21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# frozen_string_literal: true
22

3-
43
require 'database_cleaner'
54
require 'closure_tree/test/matcher'
65
require 'tmpdir'
@@ -11,6 +10,7 @@
1110
require 'active_record'
1211
require 'active_support/core_ext/array'
1312

13+
puts "Using ActiveRecord #{ActiveRecord.gem_version} and #{RUBY_ENGINE} #{RUBY_ENGINE_VERSION} as #{RUBY_VERSION}"
1414

1515
# Start Simplecov
1616
if RUBY_ENGINE == 'ruby'
@@ -20,20 +20,25 @@
2020
end
2121
end
2222

23-
database_file = SecureRandom.hex
24-
ActiveRecord::Base.configurations = debug = {
23+
primary_database_url = ENV['DATABASE_URL'].presence || "sqlite3:///tmp/closure_tree_test"
24+
secondary_database_url = ENV['SECONDARY_DATABASE_URL'].presence || "sqlite3:///tmp/closure_tree_test-s"
25+
26+
puts "Using primary database #{primary_database_url}"
27+
puts "Using secondary database #{secondary_database_url}"
28+
29+
ActiveRecord::Base.configurations = {
2530
default_env: {
26-
url: ENV['DATABASE_URL'].presence || "sqlite3://#{Dir.tmpdir}/#{database_file}.sqlite3",
27-
properties: { allowPublicKeyRetrieval: true } # for JRuby madness
28-
},
29-
secondary_env: {
30-
url: ENV['SECONDARY_DATABASE_URL'].presence || "sqlite3://#{Dir.tmpdir}/#{database_file}-s.sqlite3",
31-
properties: { allowPublicKeyRetrieval: true } # for JRuby madness
31+
primary: {
32+
url: primary_database_url,
33+
properties: { allowPublicKeyRetrieval: true } # for JRuby madness
34+
},
35+
secondary: {
36+
url: secondary_database_url,
37+
properties: { allowPublicKeyRetrieval: true } # for JRuby madness
38+
}
3239
}
3340
}
3441

35-
puts "Testing with #{debug}"
36-
3742
# Configure ActiveRecord
3843
ActiveRecord::Migration.verbose = false
3944
ActiveRecord::Base.table_name_prefix = ENV['DB_PREFIX'].to_s
@@ -75,15 +80,12 @@ def sqlite?
7580
# disable monkey patching
7681
# see: https://relishapp.com/rspec/rspec-core/v/3-8/docs/configuration/zero-monkey-patching-mode
7782
config.disable_monkey_patching!
83+
config.before(:suite) do
84+
ENV['FLOCK_DIR'] = Dir.mktmpdir if sqlite?
85+
end
7886

79-
if sqlite?
80-
config.before(:suite) do
81-
ENV['FLOCK_DIR'] = Dir.mktmpdir
82-
end
83-
84-
config.after(:suite) do
85-
FileUtils.remove_entry_secure ENV['FLOCK_DIR']
86-
end
87+
config.after(:suite) do
88+
FileUtils.remove_entry_secure(ENV['FLOCK_DIR']) if sqlite?
8789
end
8890
end
8991

@@ -94,14 +96,24 @@ def sqlite?
9496
# See: https://github.com/ClosureTree/with_advisory_lock
9597
ENV['WITH_ADVISORY_LOCK_PREFIX'] ||= SecureRandom.hex
9698

97-
ActiveRecord::Base.connection.recreate_database("closure_tree_test") unless sqlite?
98-
puts "Testing with #{env_db} database, ActiveRecord #{ActiveRecord.gem_version} and #{RUBY_ENGINE} #{RUBY_ENGINE_VERSION} as #{RUBY_VERSION}"
9999
# Require our gem
100100
require 'closure_tree'
101+
begin
102+
ActiveRecord::Base.establish_connection(:primary)
103+
rescue
104+
ActiveRecord::Tasks::DatabaseTasks.create_current('primary')
105+
end
106+
107+
begin
108+
ActiveRecord::Base.establish_connection(:secondary)
109+
rescue
110+
ActiveRecord::Tasks::DatabaseTasks.create_current('secondary')
111+
end
101112

102113
# Load test helpers
103114
require_relative 'support/schema'
104115
require_relative 'support/models'
105116
require_relative 'support/helpers'
106117
require_relative 'support/exceed_query_limit'
107118
require_relative 'support/query_counter'
119+
puts "Testing with #{env_db} database"

spec/support/models.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def to_s
1010

1111
def add_destroyed_tag
1212
# Proof for the tests that the destroy rather than the delete method was called:
13-
DestroyedTag.create(name:)
13+
DestroyedTag.create(name: to_s)
1414
end
1515
end
1616

@@ -30,7 +30,7 @@ def to_s
3030

3131
def add_destroyed_tag
3232
# Proof for the tests that the destroy rather than the delete method was called:
33-
DestroyedTag.create(name:)
33+
DestroyedTag.create(name: to_s)
3434
end
3535
end
3636

spec/support/schema.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class ApplicationRecord < ActiveRecord::Base
77
class SecondDatabaseRecord < ActiveRecord::Base
88
self.abstract_class = true
99

10-
establish_connection :secondary_env
10+
establish_connection :secondary
1111
end
1212

1313
ActiveRecord::Schema.define(version: 0) do

test/test_helper.rb

+32-13
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,29 @@
77
require 'support/query_counter'
88
require 'parallel'
99

10-
database_file = SecureRandom.hex
11-
ActiveRecord::Base.configurations = debug = {
10+
puts "Using ActiveRecord #{ActiveRecord.gem_version} and #{RUBY_ENGINE} #{RUBY_ENGINE_VERSION} as #{RUBY_VERSION}"
11+
12+
primary_database_url = ENV['DATABASE_URL'].presence || "sqlite3:///tmp/closure_tree_test"
13+
secondary_database_url = ENV['SECONDARY_DATABASE_URL'].presence || "sqlite3:///tmp/closure_tree_test-s"
14+
15+
puts "Using primary database #{primary_database_url}"
16+
puts "Using secondary database #{secondary_database_url}"
17+
18+
ActiveRecord::Base.configurations = {
1219
default_env: {
13-
url: ENV['DATABASE_URL'].presence || "sqlite3://#{Dir.tmpdir}/#{database_file}.sqlite3",
14-
properties: { allowPublicKeyRetrieval: true } # for JRuby madness
15-
},
16-
secondary_env: {
17-
url: ENV['SECONDARY_DATABASE_URL'].presence || "sqlite3://#{Dir.tmpdir}/#{database_file}-s.sqlite3",
18-
properties: { allowPublicKeyRetrieval: true } # for JRuby madness
20+
primary: {
21+
url: primary_database_url,
22+
properties: { allowPublicKeyRetrieval: true } # for JRuby madness
23+
},
24+
secondary: {
25+
url: secondary_database_url,
26+
properties: { allowPublicKeyRetrieval: true } # for JRuby madness
27+
}
1928
}
2029
}
2130

22-
puts "Testing with #{debug}"
23-
2431
ENV['WITH_ADVISORY_LOCK_PREFIX'] ||= SecureRandom.hex
2532

26-
2733
def env_db
2834
@env_db ||= ActiveRecord::Base.connection_db_config.adapter.to_sym
2935
end
@@ -37,9 +43,9 @@ def sqlite?
3743
env_db == :sqlite3
3844
end
3945

40-
puts "Testing with #{env_db} database, ActiveRecord #{ActiveRecord.gem_version} and #{RUBY_ENGINE} #{RUBY_ENGINE_VERSION} as #{RUBY_VERSION}"
4146

4247
DatabaseCleaner.strategy = :truncation
48+
DatabaseCleaner.allow_remote_database_url = true
4349

4450
module Minitest
4551
class Spec
@@ -61,6 +67,19 @@ class Spec
6167
Thread.abort_on_exception = true
6268

6369
require 'closure_tree'
70+
begin
71+
ActiveRecord::Base.establish_connection(:primary)
72+
rescue
73+
ActiveRecord::Tasks::DatabaseTasks.create_current('primary')
74+
end
75+
76+
begin
77+
ActiveRecord::Base.establish_connection(:secondary)
78+
rescue
79+
ActiveRecord::Tasks::DatabaseTasks.create_current('secondary')
80+
end
81+
6482
require_relative '../spec/support/schema'
6583
require_relative '../spec/support/models'
66-
ActiveRecord::Base.connection.recreate_database('closure_tree_test') unless sqlite?
84+
85+
puts "Testing with #{env_db} database"

0 commit comments

Comments
 (0)