Skip to content

Commit 14de642

Browse files
committed
Add savepoint placeholder for each savepoint created
1 parent af26fc9 commit 14de642

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

test/support/query_assertions.rb

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,24 @@ def assert_queries_count(count = nil, include_schema: false, &block)
1010
queries = include_schema ? counter.log_all : counter.log
1111

1212
# Start of monkey-patch
13-
# Rails tests expect a save-point to be released at the end of the test. SQL Server does not release
14-
# save-points and so the number of queries will be off by one. This monkey patch adds a placeholder query
15-
# to the end of the queries array to account for the missing save-point release.
16-
queries.append "/* release savepoint placeholder for testing */" if queries.first =~ /SAVE TRANSACTION \S+/
13+
# Rails tests expect a save-point to be created and released. SQL Server does not release
14+
# save-points and so the number of queries will be off. This monkey patch adds a placeholder queries
15+
# to replace the missing save-point releases.
16+
grouped_savepoint_queries = [[]]
17+
18+
queries.each do |query|
19+
if query =~ /SAVE TRANSACTION \S+/
20+
grouped_savepoint_queries << [query]
21+
else
22+
grouped_savepoint_queries.last << query
23+
end
24+
end
25+
26+
grouped_savepoint_queries.each do |group|
27+
group.append "/* release savepoint placeholder for testing */" if group.first =~ /SAVE TRANSACTION \S+/
28+
end
29+
30+
queries = grouped_queries.flatten
1731
# End of monkey-patch
1832

1933
if count

0 commit comments

Comments
 (0)