mirror of
https://github.com/discourse/discourse.git
synced 2024-12-11 21:03:57 +08:00
4ea21fa2d0
This change both speeds up specs (less strings to allocate) and helps catch cases where methods in Discourse are mutating inputs. Overall we will be migrating everything to use #frozen_string_literal: true it will take a while, but this is the first and safest move in this direction
27 lines
552 B
Ruby
27 lines
552 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
|
|
@events_trigger = events_trigger = []
|
|
yield
|
|
@events_trigger = nil
|
|
events_trigger
|
|
end
|
|
|
|
def track(event_type)
|
|
events = track_events { yield }
|
|
events.find { |e| e[:event_name] == event_type }
|
|
end
|
|
|
|
end
|
|
|
|
DiscourseEvent.singleton_class.prepend DiscourseEvent::TestHelper
|