From 598a3f3e1079d072483f0b34dff5fe6f8d67a45a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Tue, 9 Sep 2014 18:56:04 +0200 Subject: [PATCH] FIX: 'disable_edit_notifications' will only disable revisions made by the system user --- app/models/post_alert_observer.rb | 2 +- spec/models/post_alert_observer_spec.rb | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/models/post_alert_observer.rb b/app/models/post_alert_observer.rb index 61bf57e6df5..1a55a596f93 100644 --- a/app/models/post_alert_observer.rb +++ b/app/models/post_alert_observer.rb @@ -41,10 +41,10 @@ class PostAlertObserver < ActiveRecord::Observer post = post_revision.post return unless post - return if SiteSetting.disable_edit_notifications return if post_revision.user.blank? return if post_revision.user_id == post.user_id return if post.topic.private_message? + return if SiteSetting.disable_edit_notifications && post_revision.user_id == Discourse::SYSTEM_USER_ID alerter.create_notification(post.user, Notification.types[:edited], post, display_username: post_revision.user.username) end diff --git a/spec/models/post_alert_observer_spec.rb b/spec/models/post_alert_observer_spec.rb index 5604feca2b0..a57830c88a0 100644 --- a/spec/models/post_alert_observer_spec.rb +++ b/spec/models/post_alert_observer_spec.rb @@ -40,11 +40,23 @@ describe PostAlertObserver do }.should change(post.user.notifications, :count).by(1) end - it 'does not notifiy a user of the revision when edit notifications are disabled' do - SiteSetting.stubs(:disable_edit_notifications).returns(true) - lambda { - post.revise(evil_trout, "world is the new body of the message") - }.should_not change(post.user.notifications, :count).by(1) + context "edit notifications are disabled" do + + before { SiteSetting.stubs(:disable_edit_notifications).returns(true) } + + + it 'notifies a user of the revision made by another user' do + lambda { + post.revise(evil_trout, "world is the new body of the message") + }.should change(post.user.notifications, :count).by(1) + end + + it 'does not notifiy a user of the revision made by the system user' do + lambda { + post.revise(Discourse.system_user, "world is the new body of the message") + }.should_not change(post.user.notifications, :count) + end + end end