Skip to content

Commit

Permalink
remove debug
Browse files Browse the repository at this point in the history
  • Loading branch information
seuros committed Jan 18, 2024
1 parent 1837fd0 commit a449cd8
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 28 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ jobs:
- activerecord_6.1
- activerecord_edge
adapter:
- '' # SQLite3
- sqlite3://tmp/closure_tree_test
- mysql2://root:root@0/closure_tree_test
- postgres://closure_tree:closure_tree@0/closure_tree_test
- postgres://postgres@0/closure_tree_test
exclude:
- ruby: '3.0'
rails: activerecord_edge
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_jruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- activerecord_7.0
- activerecord_6.1
adapter:
- '' # SQLite3
- sqlite3://tmp/closure_tree_test
- mysql2://root:root@0/closure_tree_test
- postgres://closure_tree:closure_tree@0/closure_tree_test
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_truffleruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
- activerecord_7.0
- activerecord_6.1
adapter:
- '' # SQLite3
- sqlite3://tmp/closure_tree_test
- mysql2://root:root@0/closure_tree_test
- postgres://closure_tree:closure_tree@0/closure_tree_test

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ tmp/
.ruby-*
*.iml
coverage/
.env
29 changes: 16 additions & 13 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
require 'active_record'
require 'active_support/core_ext/array'

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

# Start Simplecov
if RUBY_ENGINE == 'ruby'
Expand All @@ -20,20 +21,23 @@
end
end

database_file = SecureRandom.hex
ActiveRecord::Base.configurations = debug = {
primary_database_url = ENV['DATABASE_URL'].presence || "sqlite3://tmp/closure_tree_test"
secondary_database_url = ENV['SECONDARY_DATABASE_URL'].presence || "sqlite3://tmp/closure_tree_test-s"

puts "Using primary database #{primary_database_url}"
puts "Using secondary database #{secondary_database_url}"

ActiveRecord::Base.configurations = {
default_env: {
url: ENV['DATABASE_URL'].presence || "sqlite3://#{Dir.tmpdir}/#{database_file}.sqlite3",
url: primary_database_url ,
properties: { allowPublicKeyRetrieval: true } # for JRuby madness
},
secondary_env: {
url: ENV['SECONDARY_DATABASE_URL'].presence || "sqlite3://#{Dir.tmpdir}/#{database_file}-s.sqlite3",
url: secondary_database_url,
properties: { allowPublicKeyRetrieval: true } # for JRuby madness
}
}

puts "Testing with #{debug}"

# Configure ActiveRecord
ActiveRecord::Migration.verbose = false
ActiveRecord::Base.table_name_prefix = ENV['DB_PREFIX'].to_s
Expand Down Expand Up @@ -75,16 +79,13 @@ def sqlite?
# disable monkey patching
# see: https://relishapp.com/rspec/rspec-core/v/3-8/docs/configuration/zero-monkey-patching-mode
config.disable_monkey_patching!

if sqlite?
config.before(:suite) do
ENV['FLOCK_DIR'] = Dir.mktmpdir
ENV['FLOCK_DIR'] = Dir.mktmpdir if sqlite?
end

config.after(:suite) do
FileUtils.remove_entry_secure ENV['FLOCK_DIR']
FileUtils.remove_entry_secure(ENV['FLOCK_DIR']) if sqlite?
end
end
end

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

ActiveRecord::Base.connection.recreate_database("closure_tree_test") unless sqlite?
puts "Testing with #{env_db} database, ActiveRecord #{ActiveRecord.gem_version} and #{RUBY_ENGINE} #{RUBY_ENGINE_VERSION} as #{RUBY_VERSION}"
# Require our gem
require 'closure_tree'

ActiveRecord::Tasks::DatabaseTasks.create_current('default_env', 'test')
ActiveRecord::Tasks::DatabaseTasks.create_current('secondary_env', 'test')

# Load test helpers
require_relative 'support/schema'
require_relative 'support/models'
require_relative 'support/helpers'
require_relative 'support/exceed_query_limit'
require_relative 'support/query_counter'
puts "Testing with #{env_db} database"
4 changes: 2 additions & 2 deletions spec/support/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def to_s

def add_destroyed_tag
# Proof for the tests that the destroy rather than the delete method was called:
DestroyedTag.create(name:)
DestroyedTag.create(name: to_s)
end
end

Expand All @@ -30,7 +30,7 @@ def to_s

def add_destroyed_tag
# Proof for the tests that the destroy rather than the delete method was called:
DestroyedTag.create(name:)
DestroyedTag.create(name: to_s)
end
end

Expand Down
26 changes: 17 additions & 9 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,27 @@
require 'support/query_counter'
require 'parallel'

database_file = SecureRandom.hex
ActiveRecord::Base.configurations = debug = {
puts "Using ActiveRecord #{ActiveRecord.gem_version} and #{RUBY_ENGINE} #{RUBY_ENGINE_VERSION} as #{RUBY_VERSION}"

primary_database_url = ENV['DATABASE_URL'].presence || "sqlite3://tmp/closure_tree_test"
secondary_database_url = ENV['SECONDARY_DATABASE_URL'].presence || "sqlite3://tmp/closure_tree_test-s"

puts "Using primary database #{primary_database_url}"
puts "Using secondary database #{secondary_database_url}"

ActiveRecord::Base.configurations = {
default_env: {
url: ENV['DATABASE_URL'].presence || "sqlite3://#{Dir.tmpdir}/#{database_file}.sqlite3",
url: primary_database_url ,
properties: { allowPublicKeyRetrieval: true } # for JRuby madness
},
secondary_env: {
url: ENV['SECONDARY_DATABASE_URL'].presence || "sqlite3://#{Dir.tmpdir}/#{database_file}-s.sqlite3",
url: secondary_database_url,
properties: { allowPublicKeyRetrieval: true } # for JRuby madness
}
}

puts "Testing with #{debug}"

ENV['WITH_ADVISORY_LOCK_PREFIX'] ||= SecureRandom.hex


def env_db
@env_db ||= ActiveRecord::Base.connection_db_config.adapter.to_sym
end
Expand All @@ -37,9 +41,9 @@ def sqlite?
env_db == :sqlite3
end

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

DatabaseCleaner.strategy = :truncation
DatabaseCleaner.allow_remote_database_url = true

module Minitest
class Spec
Expand All @@ -61,6 +65,10 @@ class Spec
Thread.abort_on_exception = true

require 'closure_tree'
ActiveRecord::Tasks::DatabaseTasks.create_current('default_env', 'test')
ActiveRecord::Tasks::DatabaseTasks.create_current('secondary_env', 'test')

require_relative '../spec/support/schema'
require_relative '../spec/support/models'
ActiveRecord::Base.connection.recreate_database('closure_tree_test') unless sqlite?

puts "Testing with #{env_db} database"

0 comments on commit a449cd8

Please sign in to comment.