aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorEileen M. Uchitelle <eileencodes@users.noreply.github.com>2019-04-08 11:26:31 -0400
committerGitHub <noreply@github.com>2019-04-08 11:26:31 -0400
commit27c3ad0ac0ae6a493a6feed86dfa721a1783c17c (patch)
tree5215051929fa10803a6b76bcda948f7e06d545c1 /activerecord/test
parent3f0a25ad830705b4d807d95af10189055e8c3791 (diff)
parent54dce6870de23110cdf251d8f71a8e1a57dea7bb (diff)
downloadrails-27c3ad0ac0ae6a493a6feed86dfa721a1783c17c.tar.gz
rails-27c3ad0ac0ae6a493a6feed86dfa721a1783c17c.tar.bz2
rails-27c3ad0ac0ae6a493a6feed86dfa721a1783c17c.zip
Merge pull request #35892 from ryohashimoto/bulk_insert_logs
Improve log messages for #insert_all` / `#upsert_all` etc. methods
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/insert_all_test.rb49
1 files changed, 49 insertions, 0 deletions
diff --git a/activerecord/test/cases/insert_all_test.rb b/activerecord/test/cases/insert_all_test.rb
index 61fbda1f0f..f24c63031c 100644
--- a/activerecord/test/cases/insert_all_test.rb
+++ b/activerecord/test/cases/insert_all_test.rb
@@ -181,6 +181,42 @@ class InsertAllTest < ActiveRecord::TestCase
end
end
+ def test_insert_logs_message_including_model_name
+ skip unless supports_insert_conflict_target?
+
+ capture_log_output do |output|
+ Book.insert(name: "Rework", author_id: 1)
+ assert_match "Book Insert", output.string
+ end
+ end
+
+ def test_insert_all_logs_message_including_model_name
+ skip unless supports_insert_conflict_target?
+
+ capture_log_output do |output|
+ Book.insert_all [{ name: "Remote", author_id: 1 }, { name: "Renote", author_id: 1 }]
+ assert_match "Book Bulk Insert", output.string
+ end
+ end
+
+ def test_upsert_logs_message_including_model_name
+ skip unless supports_insert_on_duplicate_update?
+
+ capture_log_output do |output|
+ Book.upsert(name: "Remote", author_id: 1)
+ assert_match "Book Upsert", output.string
+ end
+ end
+
+ def test_upsert_all_logs_message_including_model_name
+ skip unless supports_insert_on_duplicate_update?
+
+ capture_log_output do |output|
+ Book.upsert_all [{ name: "Remote", author_id: 1 }, { name: "Renote", author_id: 1 }]
+ assert_match "Book Bulk Upsert", output.string
+ end
+ end
+
def test_upsert_all_updates_existing_records
skip unless supports_insert_on_duplicate_update?
@@ -224,4 +260,17 @@ class InsertAllTest < ActiveRecord::TestCase
Book.insert_all! [{ unknown_attribute: "Test" }]
end
end
+
+ private
+
+ def capture_log_output
+ output = StringIO.new
+ old_logger, ActiveRecord::Base.logger = ActiveRecord::Base.logger, ActiveSupport::Logger.new(output)
+
+ begin
+ yield output
+ ensure
+ ActiveRecord::Base.logger = old_logger
+ end
+ end
end