mirror of
https://github.com/discourse/discourse.git
synced 2024-12-01 11:53:44 +08:00
78427e0797
Follow-up to 02ce9b8a62
36 lines
783 B
Ruby
36 lines
783 B
Ruby
# frozen_string_literal: true
|
|
|
|
module DiscourseEvent::TestHelper
|
|
def trigger(event_name, *params)
|
|
super(event_name, *params)
|
|
|
|
if @events_trigger
|
|
@events_trigger << { event_name: event_name, params: params }
|
|
end
|
|
end
|
|
|
|
def track_events(event_name = nil, args: nil)
|
|
@events_trigger = events_trigger = []
|
|
yield
|
|
@events_trigger = nil
|
|
|
|
if event_name
|
|
events_trigger = events_trigger.filter do |event|
|
|
next if event[:event_name] != event_name
|
|
next if args && event[:params] != args
|
|
true
|
|
end
|
|
end
|
|
|
|
events_trigger
|
|
end
|
|
|
|
def track(event_name, args: nil)
|
|
events = track_events(event_name, args: args) { yield }
|
|
events.first
|
|
end
|
|
|
|
end
|
|
|
|
DiscourseEvent.singleton_class.prepend DiscourseEvent::TestHelper
|