Skip to content

Commit b8c6780

Browse files
authored
Merge pull request rails#41898 from kamipo/delete_all_payload_name
Improve the payload name for `delete_all` to more appropriate
2 parents ddab225 + 899ecd4 commit b8c6780

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

activerecord/lib/active_record/relation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ def delete_all
606606

607607
stmt = arel.compile_delete(table[primary_key])
608608

609-
klass.connection.delete(stmt, "#{klass} Destroy").tap { reset }
609+
klass.connection.delete(stmt, "#{klass} Delete All").tap { reset }
610610
end
611611

612612
# Finds and destroys all records matching the specified conditions.

activerecord/test/cases/instrumentation_test.rb

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_payload_name_on_load
1313
Book.create(name: "test book")
1414
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
1515
event = ActiveSupport::Notifications::Event.new(*args)
16-
if event.payload[:sql].match "SELECT"
16+
if event.payload[:sql].match?("SELECT")
1717
assert_equal "Book Load", event.payload[:name]
1818
end
1919
end
@@ -25,7 +25,7 @@ def test_payload_name_on_load
2525
def test_payload_name_on_create
2626
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
2727
event = ActiveSupport::Notifications::Event.new(*args)
28-
if event.payload[:sql].match "INSERT"
28+
if event.payload[:sql].match?("INSERT")
2929
assert_equal "Book Create", event.payload[:name]
3030
end
3131
end
@@ -37,7 +37,7 @@ def test_payload_name_on_create
3737
def test_payload_name_on_update
3838
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
3939
event = ActiveSupport::Notifications::Event.new(*args)
40-
if event.payload[:sql].match "UPDATE"
40+
if event.payload[:sql].match?("UPDATE")
4141
assert_equal "Book Update", event.payload[:name]
4242
end
4343
end
@@ -50,11 +50,10 @@ def test_payload_name_on_update
5050
def test_payload_name_on_update_all
5151
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
5252
event = ActiveSupport::Notifications::Event.new(*args)
53-
if event.payload[:sql].match "UPDATE"
53+
if event.payload[:sql].match?("UPDATE")
5454
assert_equal "Book Update All", event.payload[:name]
5555
end
5656
end
57-
Book.create(name: "test book", format: "paperback")
5857
Book.update_all(format: "ebook")
5958
ensure
6059
ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber
@@ -63,7 +62,7 @@ def test_payload_name_on_update_all
6362
def test_payload_name_on_destroy
6463
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
6564
event = ActiveSupport::Notifications::Event.new(*args)
66-
if event.payload[:sql].match "DELETE"
65+
if event.payload[:sql].match?("DELETE")
6766
assert_equal "Book Destroy", event.payload[:name]
6867
end
6968
end
@@ -73,10 +72,22 @@ def test_payload_name_on_destroy
7372
ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber
7473
end
7574

75+
def test_payload_name_on_delete_all
76+
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
77+
event = ActiveSupport::Notifications::Event.new(*args)
78+
if event.payload[:sql].match?("DELETE")
79+
assert_equal "Book Delete All", event.payload[:name]
80+
end
81+
end
82+
Book.delete_all
83+
ensure
84+
ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber
85+
end
86+
7687
def test_payload_name_on_pluck
7788
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
7889
event = ActiveSupport::Notifications::Event.new(*args)
79-
if event.payload[:sql].match "SELECT"
90+
if event.payload[:sql].match?("SELECT")
8091
assert_equal "Book Pluck", event.payload[:name]
8192
end
8293
end
@@ -88,7 +99,7 @@ def test_payload_name_on_pluck
8899
def test_payload_name_on_count
89100
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
90101
event = ActiveSupport::Notifications::Event.new(*args)
91-
if event.payload[:sql].match "SELECT"
102+
if event.payload[:sql].match?("SELECT")
92103
assert_equal "Book Count", event.payload[:name]
93104
end
94105
end
@@ -100,7 +111,7 @@ def test_payload_name_on_count
100111
def test_payload_name_on_grouped_count
101112
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
102113
event = ActiveSupport::Notifications::Event.new(*args)
103-
if event.payload[:sql].match "SELECT"
114+
if event.payload[:sql].match?("SELECT")
104115
assert_equal "Book Count", event.payload[:name]
105116
end
106117
end

0 commit comments

Comments
 (0)