2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-01 03:19:43 -04:00
|
|
|
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
|
|
|
|
@events_trigger = events_trigger = []
|
|
|
|
yield
|
|
|
|
@events_trigger = nil
|
|
|
|
events_trigger
|
|
|
|
end
|
2019-01-03 12:03:01 -05:00
|
|
|
|
|
|
|
def track(event_type)
|
|
|
|
events = track_events { yield }
|
|
|
|
events.find { |e| e[:event_name] == event_type }
|
|
|
|
end
|
|
|
|
|
2017-06-01 03:19:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
DiscourseEvent.singleton_class.prepend DiscourseEvent::TestHelper
|