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 6ecd0c3
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 43 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:postgres@0/closure_tree_test
exclude:
- ruby: '3.0'
rails: activerecord_edge
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci_jruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ 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
- postgres://postgres:postgres@0/closure_tree_test
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci_truffleruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ 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
- postgres://postgres:postgres@0/closure_tree_test

steps:
- name: Checkout
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
54 changes: 33 additions & 21 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true


require 'database_cleaner'
require 'closure_tree/test/matcher'
require 'tmpdir'
Expand All @@ -11,6 +10,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 +20,25 @@
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",
properties: { allowPublicKeyRetrieval: true } # for JRuby madness
},
secondary_env: {
url: ENV['SECONDARY_DATABASE_URL'].presence || "sqlite3://#{Dir.tmpdir}/#{database_file}-s.sqlite3",
properties: { allowPublicKeyRetrieval: true } # for JRuby madness
primary: {
url: primary_database_url,
properties: { allowPublicKeyRetrieval: true } # for JRuby madness
},
secondary: {
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,15 +80,12 @@ 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!
config.before(:suite) do
ENV['FLOCK_DIR'] = Dir.mktmpdir if sqlite?
end

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

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

Expand All @@ -94,14 +96,24 @@ 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'
begin
ActiveRecord::Base.establish_connection(:primary)
rescue
ActiveRecord::Tasks::DatabaseTasks.create_current('primary')
end

begin
ActiveRecord::Base.establish_connection(:secondary)
rescue
ActiveRecord::Tasks::DatabaseTasks.create_current('secondary')
end

# 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
2 changes: 1 addition & 1 deletion spec/support/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ApplicationRecord < ActiveRecord::Base
class SecondDatabaseRecord < ActiveRecord::Base
self.abstract_class = true

establish_connection :secondary_env
establish_connection :secondary
end

ActiveRecord::Schema.define(version: 0) do
Expand Down
45 changes: 32 additions & 13 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,29 @@
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",
properties: { allowPublicKeyRetrieval: true } # for JRuby madness
},
secondary_env: {
url: ENV['SECONDARY_DATABASE_URL'].presence || "sqlite3://#{Dir.tmpdir}/#{database_file}-s.sqlite3",
properties: { allowPublicKeyRetrieval: true } # for JRuby madness
primary: {
url: primary_database_url,
properties: { allowPublicKeyRetrieval: true } # for JRuby madness
},
secondary: {
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 +43,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 +67,19 @@ class Spec
Thread.abort_on_exception = true

require 'closure_tree'
begin
ActiveRecord::Base.establish_connection(:primary)
rescue
ActiveRecord::Tasks::DatabaseTasks.create_current('primary')
end

begin
ActiveRecord::Base.establish_connection(:secondary)
rescue
ActiveRecord::Tasks::DatabaseTasks.create_current('secondary')
end

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 6ecd0c3

Please sign in to comment.