diff options
author | Eileen M. Uchitelle <eileencodes@users.noreply.github.com> | 2017-09-20 18:38:57 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-20 18:38:57 -0400 |
commit | 55e50f7c7819ee5d3234c47e34b5e20196ac24b7 (patch) | |
tree | 254aa2b31fe814bbf11f175750631d91257c1c6d /activerecord/test | |
parent | aa0c8778dcd8ce7ab5aed082d7900e6ab87f1d91 (diff) | |
parent | fda9df7b4e328ed2bfc3dad05899ef6269495688 (diff) | |
download | rails-55e50f7c7819ee5d3234c47e34b5e20196ac24b7.tar.gz rails-55e50f7c7819ee5d3234c47e34b5e20196ac24b7.tar.bz2 rails-55e50f7c7819ee5d3234c47e34b5e20196ac24b7.zip |
Merge pull request #30619 from jagthedrummer/jeremy/instrumentation-payload-names
Update payload names for `sql.active_record` instrumentation to be more descriptive.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/instrumentation_test.rb | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/activerecord/test/cases/instrumentation_test.rb b/activerecord/test/cases/instrumentation_test.rb new file mode 100644 index 0000000000..86ffe8b0d7 --- /dev/null +++ b/activerecord/test/cases/instrumentation_test.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +require "cases/helper" +require "models/book" + +module ActiveRecord + class InstrumentationTest < ActiveRecord::TestCase + def test_payload_name_on_load + Book.create(name: "test book") + subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args| + event = ActiveSupport::Notifications::Event.new *args + if event.payload[:sql].match "SELECT" + assert_equal "Book Load", event.payload[:name] + end + end + Book.first + ensure + ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber + end + + def test_payload_name_on_create + subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args| + event = ActiveSupport::Notifications::Event.new *args + if event.payload[:sql].match "INSERT" + assert_equal "Book Create", event.payload[:name] + end + end + Book.create(name: "test book") + ensure + ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber + end + + def test_payload_name_on_update + subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args| + event = ActiveSupport::Notifications::Event.new *args + if event.payload[:sql].match "UPDATE" + assert_equal "Book Update", event.payload[:name] + end + end + book = Book.create(name: "test book") + book.update_attribute(:name, "new name") + ensure + ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber + end + + def test_payload_name_on_update_all + subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args| + event = ActiveSupport::Notifications::Event.new *args + if event.payload[:sql].match "UPDATE" + assert_equal "Book Update All", event.payload[:name] + end + end + Book.create(name: "test book") + Book.update_all(name: "new name") + ensure + ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber + end + + def test_payload_name_on_destroy + subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args| + event = ActiveSupport::Notifications::Event.new *args + if event.payload[:sql].match "DELETE" + assert_equal "Book Destroy", event.payload[:name] + end + end + book = Book.create(name: "test book") + book.destroy + ensure + ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber + end + end +end |