diff --git a/app/models/user_email_observer.rb b/app/models/user_email_observer.rb index e2389f5bb4f..3f24c6c5684 100644 --- a/app/models/user_email_observer.rb +++ b/app/models/user_email_observer.rb @@ -41,7 +41,6 @@ class UserEmailObserver < ActiveRecord::Observer def enqueue(type) return unless notification.user.email_direct? - Jobs.enqueue_in(delay, :user_email, type: type, @@ -50,7 +49,8 @@ class UserEmailObserver < ActiveRecord::Observer end def enqueue_private(type) - return unless (notification.user.email_direct? && notification.user.email_private_messages?) + return unless notification.user.email_private_messages? + Jobs.enqueue_in(delay, :user_email, type: type, diff --git a/spec/models/user_email_observer_spec.rb b/spec/models/user_email_observer_spec.rb index 20c632e1293..ece539e7d2e 100644 --- a/spec/models/user_email_observer_spec.rb +++ b/spec/models/user_email_observer_spec.rb @@ -98,6 +98,24 @@ describe UserEmailObserver do end + context 'private_message' do + + let(:user) { Fabricate(:user) } + let!(:notification) { Fabricate(:notification, user: user, notification_type: 6) } + + it "enqueues a job for the email" do + Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, type: :user_private_message, user_id: notification.user_id, notification_id: notification.id) + UserEmailObserver.send(:new).after_commit(notification) + end + + it "doesn't enqueue an email if the user has private message emails disabled" do + user.expects(:email_private_messages?).returns(false) + Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, has_entry(type: :user_private_message)).never + UserEmailObserver.send(:new).after_commit(notification) + end + + end + context 'user_invited_to_topic' do let(:user) { Fabricate(:user) }