Skip to content

Commit

Permalink
skip PRAGMA table_info query
Browse files Browse the repository at this point in the history
  • Loading branch information
khiav223577 committed Sep 2, 2023
1 parent 4d7727d commit f947b81
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ def user_destroy_dependents_count
def assert_queries(expected_count, event_key = 'sql.active_record')
sqls = []
subscriber = ActiveSupport::Notifications.subscribe(event_key) do |_, _, _, _, payload|
sqls << " ● #{payload[:sql]}" if payload[:sql] !~ /\A(?:BEGIN TRANSACTION|COMMIT TRANSACTION|BEGIN|COMMIT|PRAGMA table_info)\z/i
next if payload[:sql].start_with?('PRAGMA table_info')
next if payload[:sql] =~ /\A(?:BEGIN TRANSACTION|COMMIT TRANSACTION|BEGIN|COMMIT)\z/i

sqls << " ● #{payload[:sql]}"
end
yield
if expected_count != sqls.size # show all sql queries if query count doesn't equal to expected count.
assert_equal "expect #{expected_count} queries, but have #{sqls.size}", "\n#{sqls.join("\n").gsub('"', "'")}\n"
assert_equal "expect #{expected_count} queries, but have #{sqls.size}", "\n#{sqls.join("\n").tr('"', "'")}\n"
end
assert_equal expected_count, sqls.size
ensure
Expand Down

0 comments on commit f947b81

Please sign in to comment.