mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 12:28:59 +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.
39 lines
1.1 KiB
Ruby
39 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe Jobs::SendSystemMessage do
|
|
it "raises an error without a user_id" do
|
|
expect { Jobs::SendSystemMessage.new.execute(message_type: "welcome_invite") }.to raise_error(
|
|
Discourse::InvalidParameters,
|
|
)
|
|
end
|
|
|
|
it "raises an error without a message_type" do
|
|
expect { Jobs::SendSystemMessage.new.execute(user_id: 1234) }.to raise_error(
|
|
Discourse::InvalidParameters,
|
|
)
|
|
end
|
|
|
|
context "with valid parameters" do
|
|
fab!(:user)
|
|
|
|
it "should call SystemMessage.create" do
|
|
SystemMessage.any_instance.expects(:create).with("welcome_invite", {})
|
|
Jobs::SendSystemMessage.new.execute(user_id: user.id, message_type: "welcome_invite")
|
|
end
|
|
|
|
it "can send message parameters" do
|
|
options = {
|
|
url: "/t/no-spammers-please/123",
|
|
edit_delay: 5,
|
|
flag_reason: "Flagged by community",
|
|
}
|
|
SystemMessage.any_instance.expects(:create).with("post_hidden", options)
|
|
Jobs::SendSystemMessage.new.execute(
|
|
user_id: user.id,
|
|
message_type: "post_hidden",
|
|
message_options: options,
|
|
)
|
|
end
|
|
end
|
|
end
|