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:
commit
bd5edc2970
3 changed files with 24 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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) &&
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue