2013-02-06 03:16:51 +08:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe UserEmailObserver do
|
|
|
|
|
|
|
|
context 'user_mentioned' do
|
|
|
|
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
let!(:notification) { Fabricate(:notification, user: user) }
|
|
|
|
|
|
|
|
it "enqueues a job for the email" do
|
2013-08-27 09:52:09 +08:00
|
|
|
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, type: :user_mentioned, user_id: notification.user_id, notification_id: notification.id)
|
2013-08-26 12:55:35 +08:00
|
|
|
UserEmailObserver.send(:new).after_commit(notification)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "enqueue a delayed job for users that are online" do
|
|
|
|
user.last_seen_at = 1.minute.ago
|
2013-02-06 03:16:51 +08:00
|
|
|
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, type: :user_mentioned, user_id: notification.user_id, notification_id: notification.id)
|
2013-08-24 19:21:39 +08:00
|
|
|
UserEmailObserver.send(:new).after_commit(notification)
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't enqueue an email if the user has mention emails disabled" do
|
|
|
|
user.expects(:email_direct?).returns(false)
|
|
|
|
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, has_entry(type: :user_mentioned)).never
|
2013-08-24 19:21:39 +08:00
|
|
|
UserEmailObserver.send(:new).after_commit(notification)
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-02-28 04:38:44 +08:00
|
|
|
context 'posted' do
|
|
|
|
|
|
|
|
let(:user) { Fabricate(:user) }
|
2013-08-24 19:21:39 +08:00
|
|
|
let!(:notification) { Fabricate(:notification, user: user, notification_type: 9) }
|
2013-02-28 04:38:44 +08:00
|
|
|
|
|
|
|
it "enqueues a job for the email" do
|
2013-08-27 09:52:09 +08:00
|
|
|
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, type: :user_posted, user_id: notification.user_id, notification_id: notification.id)
|
2013-08-24 19:21:39 +08:00
|
|
|
UserEmailObserver.send(:new).after_commit(notification)
|
2013-02-28 04:38:44 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't enqueue an email if the user has mention emails disabled" do
|
|
|
|
user.expects(:email_direct?).returns(false)
|
|
|
|
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, has_entry(type: :user_posted)).never
|
2013-08-24 19:21:39 +08:00
|
|
|
UserEmailObserver.send(:new).after_commit(notification)
|
2013-02-28 04:38:44 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
context 'user_replied' do
|
|
|
|
|
|
|
|
let(:user) { Fabricate(:user) }
|
2013-08-24 19:21:39 +08:00
|
|
|
let!(:notification) { Fabricate(:notification, user: user, notification_type: 2) }
|
2013-02-06 03:16:51 +08:00
|
|
|
|
|
|
|
it "enqueues a job for the email" do
|
2013-08-27 09:52:09 +08:00
|
|
|
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, type: :user_replied, user_id: notification.user_id, notification_id: notification.id)
|
2013-08-24 19:21:39 +08:00
|
|
|
UserEmailObserver.send(:new).after_commit(notification)
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't enqueue an email if the user has mention emails disabled" do
|
|
|
|
user.expects(:email_direct?).returns(false)
|
|
|
|
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, has_entry(type: :user_replied)).never
|
2013-08-24 19:21:39 +08:00
|
|
|
UserEmailObserver.send(:new).after_commit(notification)
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'user_quoted' do
|
|
|
|
|
|
|
|
let(:user) { Fabricate(:user) }
|
2013-08-24 19:21:39 +08:00
|
|
|
let!(:notification) { Fabricate(:notification, user: user, notification_type: 3) }
|
2013-02-06 03:16:51 +08:00
|
|
|
|
|
|
|
it "enqueues a job for the email" do
|
2013-08-27 09:52:09 +08:00
|
|
|
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, type: :user_quoted, user_id: notification.user_id, notification_id: notification.id)
|
2013-08-24 19:21:39 +08:00
|
|
|
UserEmailObserver.send(:new).after_commit(notification)
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't enqueue an email if the user has mention emails disabled" do
|
|
|
|
user.expects(:email_direct?).returns(false)
|
2013-08-27 09:52:09 +08:00
|
|
|
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, has_entry(type: :user_quoted)).never
|
2013-08-24 19:21:39 +08:00
|
|
|
UserEmailObserver.send(:new).after_commit(notification)
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'email_user_invited_to_private_message' do
|
|
|
|
|
|
|
|
let(:user) { Fabricate(:user) }
|
2013-08-24 19:21:39 +08:00
|
|
|
let!(:notification) { Fabricate(:notification, user: user, notification_type: 7) }
|
2013-02-06 03:16:51 +08:00
|
|
|
|
|
|
|
it "enqueues a job for the email" do
|
2013-08-27 09:52:09 +08:00
|
|
|
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, type: :user_invited_to_private_message, user_id: notification.user_id, notification_id: notification.id)
|
2013-08-24 19:21:39 +08:00
|
|
|
UserEmailObserver.send(:new).after_commit(notification)
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't enqueue an email if the user has mention emails disabled" do
|
|
|
|
user.expects(:email_direct?).returns(false)
|
2013-08-27 09:52:09 +08:00
|
|
|
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, has_entry(type: :user_invited_to_private_message)).never
|
2013-08-24 19:21:39 +08:00
|
|
|
UserEmailObserver.send(:new).after_commit(notification)
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2015-03-31 02:36:47 +08:00
|
|
|
context 'user_invited_to_topic' do
|
|
|
|
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
let!(:notification) { Fabricate(:notification, user: user, notification_type: 13) }
|
|
|
|
|
|
|
|
it "enqueues a job for the email" do
|
|
|
|
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, type: :user_invited_to_topic, 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 mention emails disabled" do
|
|
|
|
user.expects(:email_direct?).returns(false)
|
|
|
|
Jobs.expects(:enqueue_in).with(SiteSetting.email_time_window_mins.minutes, :user_email, has_entry(type: :user_invited_to_topic)).never
|
|
|
|
UserEmailObserver.send(:new).after_commit(notification)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-08-26 12:55:35 +08:00
|
|
|
end
|