@@ -57,6 +57,13 @@ def test_value_limit_violations_are_translated_to_specific_exception_coerced
5757 assert_not_nil error . cause
5858 end
5959 end
60+
61+ # Fix randomly failing test. The loading of the model's schema was affecting the test.
62+ coerce_tests! :test_errors_when_an_insert_query_is_called_while_preventing_writes
63+ def test_errors_when_an_insert_query_is_called_while_preventing_writes_coerced
64+ Subscriber . send ( :load_schema )
65+ original_test_errors_when_an_insert_query_is_called_while_preventing_writes
66+ end
6067 end
6168end
6269
@@ -253,20 +260,11 @@ def test_binds_are_logged_coerced
253260
254261module ActiveRecord
255262 class InstrumentationTest < ActiveRecord ::TestCase
256- # This fails randomly due to schema cache being lost?
263+ # Fix randomly failing test. The loading of the model's schema was affecting the test.
257264 coerce_tests! :test_payload_name_on_load
258265 def test_payload_name_on_load_coerced
259- Book . create ( name : "test book" )
260- Book . first
261- subscriber = ActiveSupport ::Notifications . subscribe ( "sql.active_record" ) do |*args |
262- event = ActiveSupport ::Notifications ::Event . new ( *args )
263- if event . payload [ :sql ] . match "SELECT"
264- assert_equal "Book Load" , event . payload [ :name ]
265- end
266- end
267- Book . first
268- ensure
269- ActiveSupport ::Notifications . unsubscribe ( subscriber ) if subscriber
266+ Book . send ( :load_schema )
267+ original_test_payload_name_on_load
270268 end
271269 end
272270end
@@ -275,13 +273,11 @@ def test_payload_name_on_load_coerced
275273
276274
277275class CalculationsTest < ActiveRecord ::TestCase
278- # This fails randomly due to schema cache being lost?
276+ # Fix randomly failing test. The loading of the model's schema was affecting the test.
279277 coerce_tests! :test_offset_is_kept
280278 def test_offset_is_kept_coerced
281- Account . first
282- queries = assert_sql { Account . offset ( 1 ) . count }
283- assert_equal 1 , queries . length
284- assert_match ( /OFFSET/ , queries . first )
279+ Account . send ( :load_schema )
280+ original_test_offset_is_kept
285281 end
286282
287283 # Are decimal, not integer.
0 commit comments