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 a0f5d0b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
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
18 changes: 9 additions & 9 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 @@ -21,7 +22,7 @@
end

database_file = SecureRandom.hex
ActiveRecord::Base.configurations = debug = {
ActiveRecord::Base.configurations = {
default_env: {
url: ENV['DATABASE_URL'].presence || "sqlite3://#{Dir.tmpdir}/#{database_file}.sqlite3",
properties: { allowPublicKeyRetrieval: true } # for JRuby madness
Expand All @@ -32,8 +33,6 @@
}
}

puts "Testing with #{debug}"

# Configure ActiveRecord
ActiveRecord::Migration.verbose = false
ActiveRecord::Base.table_name_prefix = ENV['DB_PREFIX'].to_s
Expand Down Expand Up @@ -76,15 +75,14 @@ def sqlite?
# 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 +92,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
15 changes: 9 additions & 6 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
require 'support/query_counter'
require 'parallel'

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

database_file = SecureRandom.hex
ActiveRecord::Base.configurations = debug = {
ActiveRecord::Base.configurations = {
default_env: {
url: ENV['DATABASE_URL'].presence || "sqlite3://#{Dir.tmpdir}/#{database_file}.sqlite3",
properties: { allowPublicKeyRetrieval: true } # for JRuby madness
Expand All @@ -19,11 +21,8 @@
}
}

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 +36,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 +60,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 a0f5d0b

Please sign in to comment.