Skip to content

Commit da6238c

Browse files
authored
Redefine isolation level method as MSSSQL resets isolation after transaction (#1324)
1 parent 048734d commit da6238c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

test/cases/coerced_tests.rb

+16
Original file line numberDiff line numberDiff line change
@@ -1842,6 +1842,22 @@ class TransactionIsolationTest < ActiveRecord::TestCase
18421842

18431843
# I really need some help understanding this one.
18441844
coerce_tests! %r{repeatable read}
1845+
1846+
private
1847+
1848+
# Need to handle the resetting of the isolation level in the adapter by `SQLServerRealTransaction#commit`.
1849+
# MySQL & PostgreSQL do not reset the connection and SQLite does support transaction isolation. After that we
1850+
# can assert the number of expected isolation level events.
1851+
undef_method :assert_begin_isolation_level_event
1852+
def assert_begin_isolation_level_event(events, isolation: "READ COMMITTED")
1853+
isolation_events = events.select { _1.match(/SET TRANSACTION ISOLATION LEVEL/) }
1854+
1855+
index_of_reset_starting_isolation_level_event = isolation_events.index("SET TRANSACTION ISOLATION LEVEL READ COMMITTED")
1856+
assert index_of_reset_starting_isolation_level_event.present?
1857+
isolation_events.delete_at(index_of_reset_starting_isolation_level_event)
1858+
1859+
assert_equal 1, isolation_events.select { _1.match(/SET TRANSACTION ISOLATION LEVEL #{isolation}/) }.size
1860+
end
18451861
end
18461862

18471863
class ViewWithPrimaryKeyTest < ActiveRecord::TestCase

0 commit comments

Comments
 (0)