Skip to content

Commit 953b00f

Browse files
committed
fix again
1 parent 51fcb7d commit 953b00f

File tree

3 files changed

+38
-28
lines changed

3 files changed

+38
-28
lines changed

lib/closure_tree/test/matcher.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,3 @@ def description
8585
end
8686
end
8787
end
88-
89-
RSpec.configure do |c|
90-
c.include ClosureTree::Test::Matcher, type: :model
91-
end

test/closure_tree/matcher_test.rb

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,33 @@ class MatcherTest < ActiveSupport::TestCase
4141

4242
def assert_closure_tree(model, options = {})
4343
assert model.is_a?(Class), "Expected #{model} to be a Class"
44-
assert model.included_modules.include?(ClosureTree::Model),
45-
"Expected #{model} to include ClosureTree::Model"
44+
assert model.respond_to?(:_ct),
45+
"Expected #{model} to have closure_tree enabled"
4646

4747
if options[:ordered]
4848
order_column = options[:ordered] == true ? :sort_order : options[:ordered]
49-
assert model.closure_tree_options[:order],
49+
assert model._ct.options[:order],
5050
"Expected #{model} to be ordered"
51-
if order_column != true
52-
assert_equal order_column.to_s, model.closure_tree_options[:order],
51+
if order_column != true && order_column != :sort_order
52+
assert_equal order_column.to_s, model._ct.options[:order],
5353
"Expected #{model} to be ordered by #{order_column}"
5454
end
5555
end
5656

5757
if options.key?(:with_advisory_lock)
5858
expected = options[:with_advisory_lock]
59-
actual = model.closure_tree_options[:with_advisory_lock]
60-
assert_equal expected, actual,
61-
"Expected #{model} advisory lock to be #{expected}, but was #{actual}"
59+
actual = model._ct.options[:with_advisory_lock]
60+
if expected
61+
assert actual, "Expected #{model} to have advisory lock"
62+
else
63+
refute actual, "Expected #{model} not to have advisory lock"
64+
end
6265
end
6366
end
6467

6568
def refute_closure_tree(model)
6669
assert model.is_a?(Class), "Expected #{model} to be a Class"
67-
refute model.included_modules.include?(ClosureTree::Model),
68-
"Expected #{model} not to include ClosureTree::Model"
70+
refute model.respond_to?(:_ct),
71+
"Expected #{model} not to have closure_tree enabled"
6972
end
7073
end

test/test_helper.rb

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,34 @@
1212
require 'support/query_counter'
1313
require 'parallel'
1414
require 'timecop'
15-
require 'rails'
1615

17-
ActiveRecord::Base.configurations = {
18-
default_env: {
19-
url: ENV.fetch('DATABASE_URL', "sqlite3://#{Dir.tmpdir}/#{SecureRandom.hex}.sqlite3"),
20-
properties: { allowPublicKeyRetrieval: true } # for JRuby madness
21-
}
22-
}
16+
# Configure the database based on environment
17+
database_url = ENV['DB_ADAPTER'] || ENV['DATABASE_URL'] || "sqlite3:///:memory:"
2318

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

26-
ActiveRecord::Base.establish_connection
21+
# Parse database URL and establish connection
22+
if database_url.start_with?('sqlite3://')
23+
# SQLite needs special handling
24+
if database_url == 'sqlite3:///:memory:'
25+
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
26+
else
27+
# Create a temporary database file
28+
db_file = File.join(Dir.tmpdir, "closure_tree_test_#{SecureRandom.hex}.sqlite3")
29+
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: db_file)
30+
end
31+
else
32+
# For MySQL and PostgreSQL, use the URL directly
33+
ActiveRecord::Base.establish_connection(database_url)
34+
end
2735

2836
def env_db
29-
@env_db ||= if ActiveRecord::Base.respond_to?(:connection_db_config)
30-
ActiveRecord::Base.connection_db_config.adapter
31-
else
32-
ActiveRecord::Base.connection_config[:adapter]
33-
end.to_sym
37+
@env_db ||= ActiveRecord::Base.connection_db_config.adapter.to_sym
3438
end
3539

3640
ActiveRecord::Migration.verbose = false
3741
ActiveRecord::Base.table_name_prefix = ENV['DB_PREFIX'].to_s
3842
ActiveRecord::Base.table_name_suffix = ENV['DB_SUFFIX'].to_s
39-
ActiveRecord::Base.establish_connection
4043

4144
# Use in specs to skip some tests
4245
def sqlite?
@@ -65,6 +68,14 @@ class Spec
6568
end
6669

6770
class ActiveSupport::TestCase
71+
setup do
72+
DatabaseCleaner.start
73+
end
74+
75+
teardown do
76+
DatabaseCleaner.clean
77+
end
78+
6879
def exceed_query_limit(num, &block)
6980
counter = QueryCounter.new
7081
ActiveSupport::Notifications.subscribed(counter.to_proc, 'sql.active_record', &block)

0 commit comments

Comments
 (0)