Skip to content

Commit

Permalink
Don't swallow errors when failing to create message for post action.
Browse files Browse the repository at this point in the history
  • Loading branch information
tgxworld committed Dec 19, 2017
1 parent b39d3a8 commit 30ddc1f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/post_action.rb
Expand Up @@ -255,7 +255,7 @@ def self.create_message_for_post_action(user, post, post_action_type_id, opts)
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)
Expand Down
21 changes: 20 additions & 1 deletion spec/models/post_action_spec.rb
Expand Up @@ -515,7 +515,7 @@ def value_for(user_id, dt)
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
Expand All @@ -528,6 +528,25 @@ def value_for(user_id, dt)
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
Expand Down

1 comment on commit 30ddc1f

@discoursebot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/custom-flag-not-showing-text/76244/18

Please sign in to comment.