FIX: Do not trigger post alerts for empty posts. ()

This commit is contained in:
Bianca Nenciu 2019-03-15 18:58:43 +02:00 committed by Régis Hanol
parent e57138354d
commit 5114ef958a
2 changed files with 26 additions and 1 deletions
app/jobs/regular
spec/components

@ -5,7 +5,7 @@ module Jobs
def execute(args)
post = Post.find_by(id: args[:post_id])
if post&.topic
if post&.topic && post.raw.present?
opts = args[:options] || {}
new_record = true == args[:new_record]
PostAlerter.new(opts).after_save_post(post, new_record)

@ -1141,6 +1141,31 @@ describe PostCreator do
post_creator = PostCreator.new(user, title: '', raw: '')
expect { post_creator.create! }.to raise_error(ActiveRecord::RecordNotSaved)
end
it "does not generate an alert for empty posts" do
Jobs.run_immediately!
user2 = Fabricate(:user)
topic = Fabricate(:private_message_topic,
topic_allowed_users: [
Fabricate.build(:topic_allowed_user, user: user),
Fabricate.build(:topic_allowed_user, user: user2)
],
)
Fabricate(:topic_user,
topic: topic,
user: user2,
notification_level: TopicUser.notification_levels[:watching]
)
expect {
PostCreator.create!(user, raw: "", topic_id: topic.id, skip_validations: true)
}.to change { user2.notifications.count }.by(0)
expect {
PostCreator.create!(user, raw: "hello world", topic_id: topic.id, skip_validations: true)
}.to change { user2.notifications.count }.by(1)
end
end
context 'private message to a user that has disabled private messages' do