Skip to content

Commit a449cd8

Browse files
committed
remove debug
1 parent 1837fd0 commit a449cd8

File tree

7 files changed

+40
-28
lines changed

7 files changed

+40
-28
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@0/closure_tree_test
5656
exclude:
5757
- ruby: '3.0'
5858
rails: activerecord_edge

.github/workflows/ci_jruby.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ 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
4848
- postgres://closure_tree:closure_tree@0/closure_tree_test
4949
steps:

.github/workflows/ci_truffleruby.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ 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
5050
- postgres://closure_tree:closure_tree@0/closure_tree_test
5151

.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

+16-13
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
require 'active_record'
1212
require 'active_support/core_ext/array'
1313

14+
puts "Using ActiveRecord #{ActiveRecord.gem_version} and #{RUBY_ENGINE} #{RUBY_ENGINE_VERSION} as #{RUBY_VERSION}"
1415

1516
# Start Simplecov
1617
if RUBY_ENGINE == 'ruby'
@@ -20,20 +21,23 @@
2021
end
2122
end
2223

23-
database_file = SecureRandom.hex
24-
ActiveRecord::Base.configurations = debug = {
24+
primary_database_url = ENV['DATABASE_URL'].presence || "sqlite3://tmp/closure_tree_test"
25+
secondary_database_url = ENV['SECONDARY_DATABASE_URL'].presence || "sqlite3://tmp/closure_tree_test-s"
26+
27+
puts "Using primary database #{primary_database_url}"
28+
puts "Using secondary database #{secondary_database_url}"
29+
30+
ActiveRecord::Base.configurations = {
2531
default_env: {
26-
url: ENV['DATABASE_URL'].presence || "sqlite3://#{Dir.tmpdir}/#{database_file}.sqlite3",
32+
url: primary_database_url ,
2733
properties: { allowPublicKeyRetrieval: true } # for JRuby madness
2834
},
2935
secondary_env: {
30-
url: ENV['SECONDARY_DATABASE_URL'].presence || "sqlite3://#{Dir.tmpdir}/#{database_file}-s.sqlite3",
36+
url: secondary_database_url,
3137
properties: { allowPublicKeyRetrieval: true } # for JRuby madness
3238
}
3339
}
3440

35-
puts "Testing with #{debug}"
36-
3741
# Configure ActiveRecord
3842
ActiveRecord::Migration.verbose = false
3943
ActiveRecord::Base.table_name_prefix = ENV['DB_PREFIX'].to_s
@@ -75,16 +79,13 @@ def sqlite?
7579
# disable monkey patching
7680
# see: https://relishapp.com/rspec/rspec-core/v/3-8/docs/configuration/zero-monkey-patching-mode
7781
config.disable_monkey_patching!
78-
79-
if sqlite?
8082
config.before(:suite) do
81-
ENV['FLOCK_DIR'] = Dir.mktmpdir
83+
ENV['FLOCK_DIR'] = Dir.mktmpdir if sqlite?
8284
end
8385

8486
config.after(:suite) do
85-
FileUtils.remove_entry_secure ENV['FLOCK_DIR']
87+
FileUtils.remove_entry_secure(ENV['FLOCK_DIR']) if sqlite?
8688
end
87-
end
8889
end
8990

9091
# Configure parallel specs
@@ -94,14 +95,16 @@ def sqlite?
9495
# See: https://github.com/ClosureTree/with_advisory_lock
9596
ENV['WITH_ADVISORY_LOCK_PREFIX'] ||= SecureRandom.hex
9697

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}"
9998
# Require our gem
10099
require 'closure_tree'
101100

101+
ActiveRecord::Tasks::DatabaseTasks.create_current('default_env', 'test')
102+
ActiveRecord::Tasks::DatabaseTasks.create_current('secondary_env', 'test')
103+
102104
# Load test helpers
103105
require_relative 'support/schema'
104106
require_relative 'support/models'
105107
require_relative 'support/helpers'
106108
require_relative 'support/exceed_query_limit'
107109
require_relative 'support/query_counter'
110+
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

test/test_helper.rb

+17-9
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,27 @@
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",
20+
url: primary_database_url ,
1421
properties: { allowPublicKeyRetrieval: true } # for JRuby madness
1522
},
1623
secondary_env: {
17-
url: ENV['SECONDARY_DATABASE_URL'].presence || "sqlite3://#{Dir.tmpdir}/#{database_file}-s.sqlite3",
24+
url: secondary_database_url,
1825
properties: { allowPublicKeyRetrieval: true } # for JRuby madness
1926
}
2027
}
2128

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

26-
2731
def env_db
2832
@env_db ||= ActiveRecord::Base.connection_db_config.adapter.to_sym
2933
end
@@ -37,9 +41,9 @@ def sqlite?
3741
env_db == :sqlite3
3842
end
3943

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

4245
DatabaseCleaner.strategy = :truncation
46+
DatabaseCleaner.allow_remote_database_url = true
4347

4448
module Minitest
4549
class Spec
@@ -61,6 +65,10 @@ class Spec
6165
Thread.abort_on_exception = true
6266

6367
require 'closure_tree'
68+
ActiveRecord::Tasks::DatabaseTasks.create_current('default_env', 'test')
69+
ActiveRecord::Tasks::DatabaseTasks.create_current('secondary_env', 'test')
70+
6471
require_relative '../spec/support/schema'
6572
require_relative '../spec/support/models'
66-
ActiveRecord::Base.connection.recreate_database('closure_tree_test') unless sqlite?
73+
74+
puts "Testing with #{env_db} database"

0 commit comments

Comments
 (0)