mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #41898 from kamipo/delete_all_payload_name
Improve the payload name for `delete_all` to more appropriate
This commit is contained in:
commit
b8c67807b4
2 changed files with 21 additions and 10 deletions
|
@ -606,7 +606,7 @@ module ActiveRecord
|
||||||
|
|
||||||
stmt = arel.compile_delete(table[primary_key])
|
stmt = arel.compile_delete(table[primary_key])
|
||||||
|
|
||||||
klass.connection.delete(stmt, "#{klass} Destroy").tap { reset }
|
klass.connection.delete(stmt, "#{klass} Delete All").tap { reset }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Finds and destroys all records matching the specified conditions.
|
# Finds and destroys all records matching the specified conditions.
|
||||||
|
|
|
@ -13,7 +13,7 @@ module ActiveRecord
|
||||||
Book.create(name: "test book")
|
Book.create(name: "test book")
|
||||||
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
|
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
|
||||||
event = ActiveSupport::Notifications::Event.new(*args)
|
event = ActiveSupport::Notifications::Event.new(*args)
|
||||||
if event.payload[:sql].match "SELECT"
|
if event.payload[:sql].match?("SELECT")
|
||||||
assert_equal "Book Load", event.payload[:name]
|
assert_equal "Book Load", event.payload[:name]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -25,7 +25,7 @@ module ActiveRecord
|
||||||
def test_payload_name_on_create
|
def test_payload_name_on_create
|
||||||
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
|
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
|
||||||
event = ActiveSupport::Notifications::Event.new(*args)
|
event = ActiveSupport::Notifications::Event.new(*args)
|
||||||
if event.payload[:sql].match "INSERT"
|
if event.payload[:sql].match?("INSERT")
|
||||||
assert_equal "Book Create", event.payload[:name]
|
assert_equal "Book Create", event.payload[:name]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -37,7 +37,7 @@ module ActiveRecord
|
||||||
def test_payload_name_on_update
|
def test_payload_name_on_update
|
||||||
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
|
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
|
||||||
event = ActiveSupport::Notifications::Event.new(*args)
|
event = ActiveSupport::Notifications::Event.new(*args)
|
||||||
if event.payload[:sql].match "UPDATE"
|
if event.payload[:sql].match?("UPDATE")
|
||||||
assert_equal "Book Update", event.payload[:name]
|
assert_equal "Book Update", event.payload[:name]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -50,11 +50,10 @@ module ActiveRecord
|
||||||
def test_payload_name_on_update_all
|
def test_payload_name_on_update_all
|
||||||
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
|
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
|
||||||
event = ActiveSupport::Notifications::Event.new(*args)
|
event = ActiveSupport::Notifications::Event.new(*args)
|
||||||
if event.payload[:sql].match "UPDATE"
|
if event.payload[:sql].match?("UPDATE")
|
||||||
assert_equal "Book Update All", event.payload[:name]
|
assert_equal "Book Update All", event.payload[:name]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Book.create(name: "test book", format: "paperback")
|
|
||||||
Book.update_all(format: "ebook")
|
Book.update_all(format: "ebook")
|
||||||
ensure
|
ensure
|
||||||
ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber
|
ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber
|
||||||
|
@ -63,7 +62,7 @@ module ActiveRecord
|
||||||
def test_payload_name_on_destroy
|
def test_payload_name_on_destroy
|
||||||
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
|
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
|
||||||
event = ActiveSupport::Notifications::Event.new(*args)
|
event = ActiveSupport::Notifications::Event.new(*args)
|
||||||
if event.payload[:sql].match "DELETE"
|
if event.payload[:sql].match?("DELETE")
|
||||||
assert_equal "Book Destroy", event.payload[:name]
|
assert_equal "Book Destroy", event.payload[:name]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -73,10 +72,22 @@ module ActiveRecord
|
||||||
ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber
|
ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_payload_name_on_delete_all
|
||||||
|
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
|
||||||
|
event = ActiveSupport::Notifications::Event.new(*args)
|
||||||
|
if event.payload[:sql].match?("DELETE")
|
||||||
|
assert_equal "Book Delete All", event.payload[:name]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Book.delete_all
|
||||||
|
ensure
|
||||||
|
ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber
|
||||||
|
end
|
||||||
|
|
||||||
def test_payload_name_on_pluck
|
def test_payload_name_on_pluck
|
||||||
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
|
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
|
||||||
event = ActiveSupport::Notifications::Event.new(*args)
|
event = ActiveSupport::Notifications::Event.new(*args)
|
||||||
if event.payload[:sql].match "SELECT"
|
if event.payload[:sql].match?("SELECT")
|
||||||
assert_equal "Book Pluck", event.payload[:name]
|
assert_equal "Book Pluck", event.payload[:name]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -88,7 +99,7 @@ module ActiveRecord
|
||||||
def test_payload_name_on_count
|
def test_payload_name_on_count
|
||||||
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
|
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
|
||||||
event = ActiveSupport::Notifications::Event.new(*args)
|
event = ActiveSupport::Notifications::Event.new(*args)
|
||||||
if event.payload[:sql].match "SELECT"
|
if event.payload[:sql].match?("SELECT")
|
||||||
assert_equal "Book Count", event.payload[:name]
|
assert_equal "Book Count", event.payload[:name]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -100,7 +111,7 @@ module ActiveRecord
|
||||||
def test_payload_name_on_grouped_count
|
def test_payload_name_on_grouped_count
|
||||||
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
|
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
|
||||||
event = ActiveSupport::Notifications::Event.new(*args)
|
event = ActiveSupport::Notifications::Event.new(*args)
|
||||||
if event.payload[:sql].match "SELECT"
|
if event.payload[:sql].match?("SELECT")
|
||||||
assert_equal "Book Count", event.payload[:name]
|
assert_equal "Book Count", event.payload[:name]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue