DEV: Ensure DiscourseEvent handlers cleaned up during specs (#11205)

This commit is contained in:
David Taylor
2020-11-11 19:46:13 +00:00
committed by GitHub
parent 24976669b8
commit 803b8933fa
7 changed files with 54 additions and 28 deletions

View File

@ -853,21 +853,22 @@ describe Group do
end
it 'triggers a user_added_to_group event' do
begin
automatic = nil
called = false
automatic = nil
called = false
DiscourseEvent.on(:user_added_to_group) do |_u, _g, options|
automatic = options[:automatic]
called = true
end
block = Proc.new do |_u, _g, options|
automatic = options[:automatic]
called = true
end
begin
DiscourseEvent.on(:user_added_to_group, &block)
group.add(user)
expect(automatic).to eql(false)
expect(called).to eq(true)
ensure
DiscourseEvent.off(:user_added_to_group)
DiscourseEvent.off(:user_added_to_group, &block)
end
end