FIX: when sending private message emails do not check email_direct setting

This commit is contained in:
Arpit Jalan 2015-06-09 13:05:26 +05:30
parent 5da5269652
commit 545f19500d
2 changed files with 20 additions and 2 deletions

View file

@ -41,7 +41,6 @@ class UserEmailObserver < ActiveRecord::Observer
def enqueue(type) def enqueue(type)
return unless notification.user.email_direct? return unless notification.user.email_direct?
Jobs.enqueue_in(delay, Jobs.enqueue_in(delay,
:user_email, :user_email,
type: type, type: type,
@ -50,7 +49,8 @@ class UserEmailObserver < ActiveRecord::Observer
end end
def enqueue_private(type) 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, Jobs.enqueue_in(delay,
:user_email, :user_email,
type: type, type: type,

View file

@ -98,6 +98,24 @@ describe UserEmailObserver do
end 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 context 'user_invited_to_topic' do
let(:user) { Fabricate(:user) } let(:user) { Fabricate(:user) }