@@ -181,6 +181,42 @@ def test_insert_all_and_upsert_all_raises_when_index_is_missing
181
181
end
182
182
end
183
183
184
+ def test_insert_logs_message_including_model_name
185
+ skip unless supports_insert_conflict_target?
186
+
187
+ capture_log_output do |output |
188
+ Book . insert ( name : "Rework" , author_id : 1 )
189
+ assert_match "Book Insert" , output . string
190
+ end
191
+ end
192
+
193
+ def test_insert_all_logs_message_including_model_name
194
+ skip unless supports_insert_conflict_target?
195
+
196
+ capture_log_output do |output |
197
+ Book . insert_all [ { name : "Remote" , author_id : 1 } , { name : "Renote" , author_id : 1 } ]
198
+ assert_match "Book Bulk Insert" , output . string
199
+ end
200
+ end
201
+
202
+ def test_upsert_logs_message_including_model_name
203
+ skip unless supports_insert_on_duplicate_update?
204
+
205
+ capture_log_output do |output |
206
+ Book . upsert ( name : "Remote" , author_id : 1 )
207
+ assert_match "Book Upsert" , output . string
208
+ end
209
+ end
210
+
211
+ def test_upsert_all_logs_message_including_model_name
212
+ skip unless supports_insert_on_duplicate_update?
213
+
214
+ capture_log_output do |output |
215
+ Book . upsert_all [ { name : "Remote" , author_id : 1 } , { name : "Renote" , author_id : 1 } ]
216
+ assert_match "Book Bulk Upsert" , output . string
217
+ end
218
+ end
219
+
184
220
def test_upsert_all_updates_existing_records
185
221
skip unless supports_insert_on_duplicate_update?
186
222
@@ -224,4 +260,17 @@ def test_insert_all_raises_on_unknown_attribute
224
260
Book . insert_all! [ { unknown_attribute : "Test" } ]
225
261
end
226
262
end
263
+
264
+ private
265
+
266
+ def capture_log_output
267
+ output = StringIO . new
268
+ old_logger , ActiveRecord ::Base . logger = ActiveRecord ::Base . logger , ActiveSupport ::Logger . new ( output )
269
+
270
+ begin
271
+ yield output
272
+ ensure
273
+ ActiveRecord ::Base . logger = old_logger
274
+ end
275
+ end
227
276
end
0 commit comments