Don't swallow errors when failing to create message for post action.

This commit is contained in:
Guo Xiang Tan 2017-12-19 10:58:26 +08:00
parent b39d3a863d
commit 30ddc1f222
2 changed files with 21 additions and 2 deletions

View File

@ -255,7 +255,7 @@ SQL
end
end
PostCreator.new(user, opts).create.try(:id)
PostCreator.new(user, opts).create!&.id
end
def self.limit_action!(user, post, post_action_type_id)

View File

@ -515,7 +515,7 @@ describe PostAction do
end
end
describe "#create_message_for_post_action" do
describe ".create_message_for_post_action" do
it "does not create a message when there is no message" do
message_id = PostAction.create_message_for_post_action(Discourse.system_user, post, PostActionType.types[:spam], {})
expect(message_id).to be_nil
@ -528,6 +528,25 @@ describe PostAction do
end
end
it "should raise the right errors when it fails to create a post" do
begin
group = Group[:moderators]
messageable_level = group.messageable_level
group.update!(messageable_level: Group::ALIAS_LEVELS[:nobody])
expect do
PostAction.create_message_for_post_action(
Fabricate(:user),
post,
PostActionType.types[:notify_moderators],
message: 'testing',
)
end.to raise_error(ActiveRecord::RecordNotSaved)
ensure
group.update!(messageable_level: messageable_level)
end
end
end
describe ".lookup_for" do