@@ -88,6 +88,26 @@ class Tag2 < ActiveRecord::Base
88
88
end
89
89
end
90
90
91
+ test "default_isolation_level but transaction overrides isolation" do
92
+ assert_nil Tag . default_isolation_level
93
+
94
+ events = [ ]
95
+ ActiveSupport ::Notifications . subscribed (
96
+ -> ( event ) { events << event . payload [ :sql ] } ,
97
+ "sql.active_record" ,
98
+ ) do
99
+ Tag . with_default_isolation_level ( :read_committed ) do
100
+ assert_equal :read_committed , Tag . default_isolation_level
101
+
102
+ Tag . transaction ( isolation : :repeatable_read ) do
103
+ Tag . create! ( name : "jon" )
104
+ end
105
+ end
106
+ end
107
+
108
+ assert_begin_isolation_level_event ( events , isolation : "REPEATABLE READ" )
109
+ end
110
+
91
111
# We are testing that a nonrepeatable read does not happen
92
112
if ActiveRecord ::Base . lease_connection . transaction_isolation_levels . include? ( :repeatable_read )
93
113
test "repeatable read" do
@@ -134,11 +154,11 @@ class Tag2 < ActiveRecord::Base
134
154
end
135
155
136
156
private
137
- def assert_begin_isolation_level_event ( events )
157
+ def assert_begin_isolation_level_event ( events , isolation : "READ COMMITTED" )
138
158
if current_adapter? ( :PostgreSQLAdapter )
139
- assert_equal 1 , events . select { _1 . match ( /BEGIN ISOLATION LEVEL READ COMMITTED / ) } . size
159
+ assert_equal 1 , events . select { _1 . match ( /BEGIN ISOLATION LEVEL #{ isolation } / ) } . size
140
160
else
141
- assert_equal 1 , events . select { _1 . match ( /SET TRANSACTION ISOLATION LEVEL READ COMMITTED / ) } . size
161
+ assert_equal 1 , events . select { _1 . match ( /SET TRANSACTION ISOLATION LEVEL #{ isolation } / ) } . size
142
162
end
143
163
end
144
164
end
0 commit comments