mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
UserEmailObserver is now removed
no big surprises here was pretty straightforward after_commit semantics sure are weird though
This commit is contained in:
@@ -69,6 +69,7 @@ describe CategoryUser do
|
||||
context 'integration' do
|
||||
before do
|
||||
ActiveRecord::Base.observers.enable :all
|
||||
NotificationEmailer.enable
|
||||
end
|
||||
|
||||
it 'should operate correctly' do
|
||||
|
||||
@@ -3,6 +3,7 @@ require 'rails_helper'
|
||||
describe Notification do
|
||||
before do
|
||||
ActiveRecord::Base.observers.enable :all
|
||||
NotificationEmailer.enable
|
||||
end
|
||||
|
||||
it { is_expected.to validate_presence_of :notification_type }
|
||||
@@ -139,21 +140,6 @@ describe Notification do
|
||||
end
|
||||
end
|
||||
|
||||
describe '@mention' do
|
||||
|
||||
it "calls email_user_mentioned on creating a notification" do
|
||||
UserEmailObserver.any_instance.expects(:after_commit).with(instance_of(Notification))
|
||||
Fabricate(:notification)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe '@mention' do
|
||||
it "calls email_user_quoted on creating a quote notification" do
|
||||
UserEmailObserver.any_instance.expects(:after_commit).with(instance_of(Notification))
|
||||
Fabricate(:quote_notification)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'private message' do
|
||||
before do
|
||||
@@ -250,6 +236,8 @@ describe Notification do
|
||||
it 'deletes notifications if post is missing or deleted' do
|
||||
|
||||
ActiveRecord::Base.observers.disable :all
|
||||
NotificationEmailer.disable
|
||||
|
||||
p = Fabricate(:post)
|
||||
p2 = Fabricate(:post)
|
||||
|
||||
|
||||
@@ -1,172 +0,0 @@
|
||||
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: "{\"a\": 1}",
|
||||
user: user,
|
||||
notification_type: Notification.types[type],
|
||||
topic: topic,
|
||||
post_number: post.post_number)
|
||||
end
|
||||
|
||||
shared_examples "enqueue" do
|
||||
|
||||
it "enqueues a job for the email" do
|
||||
Jobs.expects(:enqueue_in).with(delay, :user_email, UserEmailObserver::EmailUser.notification_params(notification,type))
|
||||
UserEmailObserver.process_notification(notification)
|
||||
end
|
||||
|
||||
context "inactive user" do
|
||||
before { notification.user.active = false }
|
||||
|
||||
it "doesn't enqueue a job" do
|
||||
Jobs.expects(:enqueue_in).with(delay, :user_email, has_entry(type: type)).never
|
||||
UserEmailObserver.process_notification(notification)
|
||||
end
|
||||
|
||||
it "enqueues a job if the user is staged" do
|
||||
notification.user.staged = true
|
||||
Jobs.expects(:enqueue_in).with(delay, :user_email, UserEmailObserver::EmailUser.notification_params(notification,type))
|
||||
UserEmailObserver.process_notification(notification)
|
||||
end
|
||||
end
|
||||
|
||||
context "active but unapproved user" do
|
||||
before do
|
||||
SiteSetting.must_approve_users = true
|
||||
notification.user.approved = false
|
||||
notification.user.active = true
|
||||
end
|
||||
|
||||
it "doesn't enqueue a job" do
|
||||
Jobs.expects(:enqueue_in).with(delay, :user_email, has_entry(type: type)).never
|
||||
UserEmailObserver.process_notification(notification)
|
||||
end
|
||||
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.process_notification(notification)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
shared_examples "enqueue_public" do
|
||||
include_examples "enqueue"
|
||||
|
||||
it "doesn't enqueue a job if the user has mention emails disabled" do
|
||||
notification.user.user_option.update_columns(email_direct: false)
|
||||
Jobs.expects(:enqueue_in).with(delay, :user_email, has_entry(type: type)).never
|
||||
UserEmailObserver.process_notification(notification)
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples "enqueue_private" do
|
||||
include_examples "enqueue"
|
||||
|
||||
it "doesn't enqueue a job if the user has private message emails disabled" do
|
||||
notification.user.user_option.update_columns(email_private_messages: false)
|
||||
Jobs.expects(:enqueue_in).with(delay, :user_email, has_entry(type: type)).never
|
||||
UserEmailObserver.process_notification(notification)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'user_mentioned' do
|
||||
let(:type) { :user_mentioned }
|
||||
let(:delay) { SiteSetting.email_time_window_mins.minutes }
|
||||
let!(:notification) { create_notification(:mentioned) }
|
||||
|
||||
include_examples "enqueue_public"
|
||||
|
||||
it "enqueue a delayed job for users that are online" do
|
||||
notification.user.last_seen_at = 1.minute.ago
|
||||
Jobs.expects(:enqueue_in).with(delay, :user_email, UserEmailObserver::EmailUser.notification_params(notification,type))
|
||||
UserEmailObserver.process_notification(notification)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'user_replied' do
|
||||
let(:type) { :user_replied }
|
||||
let(:delay) { SiteSetting.email_time_window_mins.minutes }
|
||||
let!(:notification) { create_notification(:replied) }
|
||||
|
||||
include_examples "enqueue_public"
|
||||
end
|
||||
|
||||
context 'user_quoted' do
|
||||
let(:type) { :user_quoted }
|
||||
let(:delay) { SiteSetting.email_time_window_mins.minutes }
|
||||
let!(:notification) { create_notification(:quoted) }
|
||||
|
||||
include_examples "enqueue_public"
|
||||
end
|
||||
|
||||
context 'user_linked' do
|
||||
let(:type) { :user_linked }
|
||||
let(:delay) { SiteSetting.email_time_window_mins.minutes }
|
||||
let!(:notification) { create_notification(:linked) }
|
||||
|
||||
include_examples "enqueue_public"
|
||||
end
|
||||
|
||||
context 'user_posted' do
|
||||
let(:type) { :user_posted }
|
||||
let(:delay) { SiteSetting.email_time_window_mins.minutes }
|
||||
let!(:notification) { create_notification(:posted) }
|
||||
|
||||
include_examples "enqueue_public"
|
||||
end
|
||||
|
||||
context 'user_private_message' do
|
||||
let(:type) { :user_private_message }
|
||||
let(:delay) { SiteSetting.private_email_time_window_seconds }
|
||||
let!(:notification) { create_notification(:private_message) }
|
||||
|
||||
include_examples "enqueue_private"
|
||||
|
||||
it "doesn't enqueue a job for a small action" do
|
||||
notification.data_hash["original_post_type"] = Post.types[:small_action]
|
||||
Jobs.expects(:enqueue_in).with(delay, :user_email, has_entry(type: type)).never
|
||||
UserEmailObserver.process_notification(notification)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'user_invited_to_private_message' do
|
||||
let(:type) { :user_invited_to_private_message }
|
||||
let(:delay) { SiteSetting.private_email_time_window_seconds }
|
||||
let!(:notification) { create_notification(:invited_to_private_message) }
|
||||
|
||||
include_examples "enqueue_public"
|
||||
end
|
||||
|
||||
context 'user_invited_to_topic' do
|
||||
let(:type) { :user_invited_to_topic }
|
||||
let(:delay) { SiteSetting.private_email_time_window_seconds }
|
||||
let!(:notification) { create_notification(:invited_to_topic) }
|
||||
|
||||
include_examples "enqueue_public"
|
||||
end
|
||||
|
||||
context 'watching the first post' do
|
||||
let(:type) { :user_watching_first_post }
|
||||
let(:delay) { SiteSetting.email_time_window_mins.minutes }
|
||||
let!(:notification) { create_notification(:watching_first_post) }
|
||||
|
||||
include_examples "enqueue_public"
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user