FIX: only send email notifications for regular and whisper type of posts

This commit is contained in:
Régis Hanol 2016-01-19 01:39:57 +01:00
parent 02d9ec5bde
commit 61cc776fdd
2 changed files with 26 additions and 7 deletions

View File

@ -42,8 +42,12 @@ class UserEmailObserver < ActiveRecord::Observer
private
EMAILABLE_POST_TYPES ||= Set.new [Post.types[:regular], Post.types[:whisper]]
def enqueue(type, delay=default_delay)
return unless notification.user.email_direct? && (notification.user.active? || notification.user.staged?)
return unless notification.user.email_direct?
return unless notification.user.active? || notification.user.staged?
return unless EMAILABLE_POST_TYPES.include? notification.post.try(:post_type)
Jobs.enqueue_in(delay,
:user_email,
@ -53,7 +57,9 @@ class UserEmailObserver < ActiveRecord::Observer
end
def enqueue_private(type, delay=default_delay)
return unless notification.user.email_private_messages? && (notification.user.active? || notification.user.staged?)
return unless notification.user.email_private_messages?
return unless notification.user.active? || notification.user.staged?
return unless EMAILABLE_POST_TYPES.include? notification.post.try(:post_type)
Jobs.enqueue_in(delay,
:user_email,

View File

@ -2,10 +2,13 @@ require 'rails_helper'
describe UserEmailObserver do
let(:topic) { Fabricate(:topic) }
let(:post) { Fabricate(:post, topic: topic) }
# something is off with fabricator
def create_notification(type, user=nil)
user ||= Fabricate(:user)
Notification.create(data: '', user: user, notification_type: type)
Notification.create(data: '', user: user, notification_type: type, topic: topic, post_number: post.post_number)
end
shared_examples "enqueue" do
@ -32,6 +35,16 @@ describe UserEmailObserver do
end
context "small action" do
it "doesn't enqueue a job" do
Post.any_instance.expects(:post_type).returns(Post.types[:small_action])
Jobs.expects(:enqueue_in).with(delay, :user_email, has_entry(type: type)).never
UserEmailObserver.send(:new).after_commit(notification)
end
end
end
shared_examples "enqueue_public" do