Skip to content

Commit

Permalink
adjust assert_queries method
Browse files Browse the repository at this point in the history
  • Loading branch information
khiav reoy committed Aug 19, 2023
1 parent 3d980e7 commit 44544de
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ def in_sandbox
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)\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.
Expand Down

0 comments on commit 44544de

Please sign in to comment.