diff --git a/app/services/post_alerter.rb b/app/services/post_alerter.rb index 6e480951c8e..073c2ba06bd 100644 --- a/app/services/post_alerter.rb +++ b/app/services/post_alerter.rb @@ -108,7 +108,7 @@ class PostAlerter sync_group_mentions(post, mentioned_groups) - if post.post_number == 1 + if new_record && post.post_number == 1 topic = post.topic if topic.present? diff --git a/spec/services/post_alerter_spec.rb b/spec/services/post_alerter_spec.rb index 008d7a3f043..4f7e2009755 100644 --- a/spec/services/post_alerter_spec.rb +++ b/spec/services/post_alerter_spec.rb @@ -342,10 +342,17 @@ describe PostAlerter do it "notifies the user who is following the first post category" do level = CategoryUser.notification_levels[:watching_first_post] CategoryUser.set_notification_level_for_category(user, level, category.id) - PostAlerter.post_created(post) + PostAlerter.new.after_save_post(post, true) expect(user.notifications.where(notification_type: Notification.types[:watching_first_post]).count).to eq(1) end + it "doesn't notify when the record is not new" do + level = CategoryUser.notification_levels[:watching_first_post] + CategoryUser.set_notification_level_for_category(user, level, category.id) + PostAlerter.new.after_save_post(post, false) + expect(user.notifications.where(notification_type: Notification.types[:watching_first_post]).count).to eq(0) + end + it "notifies the user who is following the first post tag" do level = TagUser.notification_levels[:watching_first_post] TagUser.change(user.id, tag.id, level)