1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #36318 from itsWill/fix_event_object_payload

Merge payload for EventObject subscribers
This commit is contained in:
Rafael França 2019-07-25 16:47:03 -04:00 committed by GitHub
commit bd5edc2970
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 1 deletions

View file

@ -218,6 +218,7 @@ module ActiveSupport
def finish(name, id, payload)
stack = Thread.current[:_event_stack]
event = stack.pop
event.payload = payload
event.finish!
@delegate.call event
end

View file

@ -52,7 +52,8 @@ module ActiveSupport
end
class Event
attr_reader :name, :time, :end, :transaction_id, :payload, :children
attr_reader :name, :time, :end, :transaction_id, :children
attr_accessor :payload
def self.clock_gettime_supported? # :nodoc:
defined?(Process::CLOCK_PROCESS_CPUTIME_ID) &&

View file

@ -41,6 +41,27 @@ module Notifications
assert_operator event.duration, :>, 0
end
def test_subscribe_to_events_where_payload_is_changed_during_instrumentation
@notifier.subscribe do |event|
assert_equal "success!", event.payload[:my_key]
end
ActiveSupport::Notifications.instrument("foo") do |payload|
payload[:my_key] = "success!"
end
end
def test_subscribe_to_events_can_handle_nested_hashes_in_the_paylaod
@notifier.subscribe do |event|
assert_equal "success!", event.payload[:some_key][:key_one]
assert_equal "great_success!", event.payload[:some_key][:key_two]
end
ActiveSupport::Notifications.instrument("foo", some_key: { key_one: "success!" }) do |payload|
payload[:some_key][:key_two] = "great_success!"
end
end
def test_subscribe_via_top_level_api
old_notifier = ActiveSupport::Notifications.notifier
ActiveSupport::Notifications.notifier = ActiveSupport::Notifications::Fanout.new