Skip to content

Commit 97ce388

Browse files
BuonOmorafiss
authored andcommitted
fix: overwrite pg method correctly in tests
1 parent 96f9771 commit 97ce388

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

test/cases/helper_cockroachdb.rb

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ def spatial_factory_store
123123
end
124124
end
125125

126-
module ARTestCaseHelper
127-
def with_cockroachdb_datetime_type(type)
126+
module SetDatetimeInCockroachDBAdapter
127+
def with_postgresql_datetime_type(type)
128128
adapter = ActiveRecord::ConnectionAdapters::CockroachDBAdapter
129129
adapter.remove_instance_variable(:@native_database_types) if adapter.instance_variable_defined?(:@native_database_types)
130130
datetime_type_was = adapter.datetime_type
@@ -135,9 +135,10 @@ def with_cockroachdb_datetime_type(type)
135135
adapter.datetime_type = datetime_type_was
136136
adapter.remove_instance_variable(:@native_database_types) if adapter.instance_variable_defined?(:@native_database_types)
137137
end
138+
alias :with_cockroachdb_datetime_type :with_postgresql_datetime_type
138139
end
139140

140-
ActiveRecord::TestCase.include(ARTestCaseHelper)
141+
ActiveRecord::TestCase.prepend(SetDatetimeInCockroachDBAdapter)
141142

142143
module Minitest
143144
module GithubActionReporterExt
@@ -156,6 +157,29 @@ def gh_link(loc)
156157
GithubActionReporter.prepend(GithubActionReporterExt)
157158
end
158159

160+
if ENV['TRACE_LIB']
161+
module TraceLibPlugin
162+
def after_setup
163+
super
164+
@tl_plugin__already_showed = {}
165+
@tl_plugin__trace = TracePoint.new(:call) do |tp|
166+
next unless tp.path.include?("activerecord-cockroachdb-adapter/lib")
167+
full_path = "#{tp.path}:#{tp.lineno}"
168+
next if @tl_plugin__already_showed[full_path]
169+
@tl_plugin__already_showed[full_path] = true
170+
puts "==> #{tp.defined_class}##{tp.method_id} at #{full_path}"
171+
end
172+
@tl_plugin__trace.enable
173+
end
174+
175+
def before_teardown
176+
@tl_plugin__trace.disable
177+
super
178+
end
179+
end
180+
MiniTest::Test.include(TraceLibPlugin)
181+
end
182+
159183
if ENV['AR_LOG']
160184
ActiveRecord::Base.logger = Logger.new(STDOUT)
161185
ActiveRecord::Base.logger.level = Logger::DEBUG

0 commit comments

Comments
 (0)