From 4492d06a9f5aa51dce842961f4397693666045d7 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Thu, 23 May 2013 11:42:41 -0400 Subject: [PATCH] Don't send notifications for moderator action posts --- app/models/post_alert_observer.rb | 4 ++-- spec/models/post_alert_observer_spec.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/models/post_alert_observer.rb b/app/models/post_alert_observer.rb index e5763c6e3d5..141ae363b94 100644 --- a/app/models/post_alert_observer.rb +++ b/app/models/post_alert_observer.rb @@ -63,8 +63,8 @@ class PostAlertObserver < ActiveRecord::Observer post.topic.all_allowed_users.reject{ |a| a.id == post.user_id }.each do |a| create_notification(a, Notification.types[:private_message], post) end - else - # If it's not a private message, notify the users + elsif post.post_type != Post.types[:moderator_action] + # If it's not a private message and it's not an automatic post caused by a moderator action, notify the users notify_post_users(post) end end diff --git a/spec/models/post_alert_observer_spec.rb b/spec/models/post_alert_observer_spec.rb index a3359dc927d..50f7beed53f 100644 --- a/spec/models/post_alert_observer_spec.rb +++ b/spec/models/post_alert_observer_spec.rb @@ -108,4 +108,16 @@ describe PostAlertObserver do end + context 'moderator action post' do + let(:user) { Fabricate(:user) } + let(:first_post) { Fabricate(:post, user: user, raw: 'A useless post for you.')} + let(:topic) { first_post.topic } + + it 'should not notify anyone' do + expect { + Fabricate(:post, topic: topic, raw: 'This topic is CLOSED', post_type: Post.types[:moderator_action]) + }.to_not change { Notification.count } + end + end + end