mirror of
https://github.com/discourse/discourse.git
synced 2024-12-22 19:23:48 +08:00
6e161d3e75
The most common thing that we do with fab! is: fab!(:thing) { Fabricate(:thing) } This commit adds a shorthand for this which is just simply: fab!(:thing) i.e. If you omit the block, then, by default, you'll get a `Fabricate`d object using the fabricator of the same name.
58 lines
1.6 KiB
Ruby
58 lines
1.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
describe Jobs::PublishGroupMembershipUpdates do
|
|
subject(:job) { described_class.new }
|
|
|
|
fab!(:user)
|
|
fab!(:group)
|
|
|
|
it "publishes events for added users" do
|
|
events =
|
|
DiscourseEvent.track_events do
|
|
job.execute(user_ids: [user.id], group_id: group.id, type: "add")
|
|
end
|
|
|
|
expect(events).to include(
|
|
event_name: :user_added_to_group,
|
|
params: [user, group, { automatic: group.automatic }],
|
|
)
|
|
end
|
|
|
|
it "publishes events for removed users" do
|
|
events =
|
|
DiscourseEvent.track_events do
|
|
job.execute(user_ids: [user.id], group_id: group.id, type: "remove")
|
|
end
|
|
|
|
expect(events).to include(event_name: :user_removed_from_group, params: [user, group])
|
|
end
|
|
|
|
it "does nothing if the group doesn't exist" do
|
|
events =
|
|
DiscourseEvent.track_events { job.execute(user_ids: [user.id], group_id: nil, type: "add") }
|
|
|
|
expect(events).not_to include(
|
|
event_name: :user_added_to_group,
|
|
params: [user, group, { automatic: group.automatic }],
|
|
)
|
|
end
|
|
|
|
it "fails when the update type is invalid" do
|
|
expect { job.execute(user_ids: [user.id], group_id: nil, type: nil) }.to raise_error(
|
|
Discourse::InvalidParameters,
|
|
)
|
|
end
|
|
|
|
it "does nothing when the user is not human" do
|
|
events =
|
|
DiscourseEvent.track_events do
|
|
job.execute(user_ids: [Discourse.system_user.id], group_id: nil, type: "add")
|
|
end
|
|
|
|
expect(events).not_to include(
|
|
event_name: :user_added_to_group,
|
|
params: [user, group, { automatic: group.automatic }],
|
|
)
|
|
end
|
|
end
|