2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2013-10-01 03:04:02 -04:00
|
|
|
require_dependency 'jobs/base'
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
describe Jobs::UserEmail do
|
|
|
|
|
|
|
|
before do
|
2016-01-26 20:19:49 -05:00
|
|
|
SiteSetting.email_time_window_mins = 10
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
2017-07-27 21:20:09 -04:00
|
|
|
let(:user) { Fabricate(:user, last_seen_at: 11.minutes.ago) }
|
|
|
|
let(:staged) { Fabricate(:user, staged: true, last_seen_at: 11.minutes.ago) }
|
|
|
|
let(:suspended) { Fabricate(:user, last_seen_at: 10.minutes.ago, suspended_at: 5.minutes.ago, suspended_till: 7.days.from_now) }
|
|
|
|
let(:anonymous) { Fabricate(:anonymous, last_seen_at: 11.minutes.ago) }
|
2013-02-05 14:16:51 -05:00
|
|
|
let(:mailer) { Mail::Message.new(to: user.email) }
|
|
|
|
|
|
|
|
it "raises an error when there is no user" do
|
2014-12-31 09:55:03 -05:00
|
|
|
expect { Jobs::UserEmail.new.execute(type: :digest) }.to raise_error(Discourse::InvalidParameters)
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "raises an error when there is no type" do
|
2014-12-31 09:55:03 -05:00
|
|
|
expect { Jobs::UserEmail.new.execute(user_id: user.id) }.to raise_error(Discourse::InvalidParameters)
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "raises an error when the type doesn't exist" do
|
2014-12-31 09:55:03 -05:00
|
|
|
expect { Jobs::UserEmail.new.execute(type: :no_method, user_id: user.id) }.to raise_error(Discourse::InvalidParameters)
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't call the mailer when the user is missing" do
|
|
|
|
UserNotifications.expects(:digest).never
|
|
|
|
Jobs::UserEmail.new.execute(type: :digest, user_id: 1234)
|
2013-02-25 11:42:20 -05:00
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
|
2015-11-06 13:19:13 -05:00
|
|
|
it "doesn't call the mailer when the user is staged" do
|
|
|
|
UserNotifications.expects(:digest).never
|
|
|
|
Jobs::UserEmail.new.execute(type: :digest, user_id: staged.id)
|
|
|
|
end
|
|
|
|
|
2017-03-08 04:06:16 -05:00
|
|
|
context "bounce score" do
|
|
|
|
|
|
|
|
it "always sends critical emails when bounce score threshold has been reached" do
|
|
|
|
email_token = Fabricate(:email_token)
|
|
|
|
user.user_stat.update(bounce_score: SiteSetting.bounce_score_threshold + 1)
|
|
|
|
|
|
|
|
Jobs::CriticalUserEmail.new.execute(type: "signup", user_id: user.id, email_token: email_token.token)
|
|
|
|
|
|
|
|
email_log = EmailLog.where(user_id: user.id).last
|
|
|
|
expect(email_log.email_type).to eq("signup")
|
|
|
|
expect(email_log.skipped).to eq(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
context 'to_address' do
|
|
|
|
it 'overwrites a to_address when present' do
|
2016-03-07 14:40:11 -05:00
|
|
|
UserNotifications.expects(:confirm_new_email).returns(mailer)
|
2013-06-10 15:33:37 -04:00
|
|
|
Email::Sender.any_instance.expects(:send)
|
2016-03-07 14:40:11 -05:00
|
|
|
Jobs::UserEmail.new.execute(type: :confirm_new_email, user_id: user.id, to_address: 'jake@adventuretime.ooo')
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(mailer.to).to eq(['jake@adventuretime.ooo'])
|
2013-02-25 11:42:20 -05:00
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "recently seen" do
|
|
|
|
let(:post) { Fabricate(:post, user: user) }
|
2013-02-25 11:42:20 -05:00
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
it "doesn't send an email to a user that's been recently seen" do
|
|
|
|
user.update_column(:last_seen_at, 9.minutes.ago)
|
2013-06-10 15:33:37 -04:00
|
|
|
Email::Sender.any_instance.expects(:send).never
|
2013-10-01 03:04:02 -04:00
|
|
|
Jobs::UserEmail.new.execute(type: :user_replied, user_id: user.id, post_id: post.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does send an email to a user that's been recently seen but has email_always set" do
|
2016-02-16 23:46:19 -05:00
|
|
|
user.update_attributes(last_seen_at: 9.minutes.ago)
|
|
|
|
user.user_option.update_attributes(email_always: true)
|
2016-06-30 21:22:07 -04:00
|
|
|
PostTiming.create!(topic_id: post.topic_id, post_number: post.post_number, user_id: user.id, msecs: 100)
|
|
|
|
|
2013-10-01 03:04:02 -04:00
|
|
|
Email::Sender.any_instance.expects(:send)
|
|
|
|
Jobs::UserEmail.new.execute(type: :user_replied, user_id: user.id, post_id: post.id)
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-28 13:01:35 -05:00
|
|
|
context "email_log" do
|
|
|
|
|
2017-08-14 12:47:33 -04:00
|
|
|
before do
|
|
|
|
SiteSetting.editing_grace_period = 0
|
|
|
|
Fabricate(:post)
|
|
|
|
end
|
2016-01-29 10:49:49 -05:00
|
|
|
|
|
|
|
it "creates an email log when the mail is sent (via Email::Sender)" do
|
2016-01-28 13:30:38 -05:00
|
|
|
last_emailed_at = user.last_emailed_at
|
|
|
|
|
2016-01-28 13:01:35 -05:00
|
|
|
expect { Jobs::UserEmail.new.execute(type: :digest, user_id: user.id) }.to change { EmailLog.count }.by(1)
|
2016-01-28 13:30:38 -05:00
|
|
|
|
2016-01-28 13:01:35 -05:00
|
|
|
email_log = EmailLog.last
|
|
|
|
expect(email_log.skipped).to eq(false)
|
|
|
|
expect(email_log.user_id).to eq(user.id)
|
2016-01-28 13:30:38 -05:00
|
|
|
|
|
|
|
# last_emailed_at should have changed
|
|
|
|
expect(email_log.user.last_emailed_at).to_not eq(last_emailed_at)
|
2016-01-28 13:01:35 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "creates an email log when the mail is skipped" do
|
2016-01-28 13:30:38 -05:00
|
|
|
last_emailed_at = user.last_emailed_at
|
2016-01-28 13:01:35 -05:00
|
|
|
user.update_columns(suspended_till: 1.year.from_now)
|
2016-01-28 13:30:38 -05:00
|
|
|
|
2016-01-28 13:01:35 -05:00
|
|
|
expect { Jobs::UserEmail.new.execute(type: :digest, user_id: user.id) }.to change { EmailLog.count }.by(1)
|
2016-01-28 13:30:38 -05:00
|
|
|
|
2016-01-28 13:01:35 -05:00
|
|
|
email_log = EmailLog.last
|
|
|
|
expect(email_log.skipped).to eq(true)
|
|
|
|
expect(email_log.skipped_reason).to be_present
|
|
|
|
expect(email_log.user_id).to eq(user.id)
|
2016-01-28 13:30:38 -05:00
|
|
|
|
|
|
|
# last_emailed_at doesn't change
|
|
|
|
expect(email_log.user.last_emailed_at).to eq(last_emailed_at)
|
2016-01-28 13:01:35 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
context 'args' do
|
2013-02-25 11:42:20 -05:00
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
it 'passes a token as an argument when a token is present' do
|
2017-07-27 21:20:09 -04:00
|
|
|
UserNotifications.expects(:forgot_password).with(user, email_token: 'asdfasdf').returns(mailer)
|
2013-06-10 15:33:37 -04:00
|
|
|
Email::Sender.any_instance.expects(:send)
|
2013-02-05 14:16:51 -05:00
|
|
|
Jobs::UserEmail.new.execute(type: :forgot_password, user_id: user.id, email_token: 'asdfasdf')
|
|
|
|
end
|
|
|
|
|
|
|
|
context "post" do
|
|
|
|
let(:post) { Fabricate(:post, user: user) }
|
|
|
|
|
|
|
|
it 'passes a post as an argument when a post_id is present' do
|
2017-07-27 21:20:09 -04:00
|
|
|
UserNotifications.expects(:user_private_message).with(user, post: post).returns(mailer)
|
2013-06-10 15:33:37 -04:00
|
|
|
Email::Sender.any_instance.expects(:send)
|
2017-01-05 03:15:55 -05:00
|
|
|
Jobs::UserEmail.new.execute(type: :user_private_message, user_id: user.id, post_id: post.id)
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't send the email if you've seen the post" do
|
2013-06-10 15:33:37 -04:00
|
|
|
Email::Sender.any_instance.expects(:send).never
|
2013-02-05 14:16:51 -05:00
|
|
|
PostTiming.record_timing(topic_id: post.topic_id, user_id: user.id, post_number: post.post_number, msecs: 6666)
|
2017-01-05 03:15:55 -05:00
|
|
|
Jobs::UserEmail.new.execute(type: :user_private_message, user_id: user.id, post_id: post.id)
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
2013-03-25 13:39:57 -04:00
|
|
|
it "doesn't send the email if the user deleted the post" do
|
2013-06-10 15:33:37 -04:00
|
|
|
Email::Sender.any_instance.expects(:send).never
|
2013-03-25 13:39:57 -04:00
|
|
|
post.update_column(:user_deleted, true)
|
2017-01-05 03:15:55 -05:00
|
|
|
Jobs::UserEmail.new.execute(type: :user_private_message, user_id: user.id, post_id: post.id)
|
2013-03-25 13:39:57 -04:00
|
|
|
end
|
|
|
|
|
2016-05-17 11:42:15 -04:00
|
|
|
it "doesn't send the email if user of the post has been deleted" do
|
|
|
|
Email::Sender.any_instance.expects(:send).never
|
|
|
|
post.update_attributes!(user_id: nil)
|
|
|
|
Jobs::UserEmail.new.execute(type: :user_replied, user_id: user.id, post_id: post.id)
|
|
|
|
end
|
|
|
|
|
2013-11-07 13:53:32 -05:00
|
|
|
context 'user is suspended' do
|
2013-10-30 15:31:16 -04:00
|
|
|
it "doesn't send email for a pm from a regular user" do
|
|
|
|
Email::Sender.any_instance.expects(:send).never
|
2017-01-05 03:15:55 -05:00
|
|
|
Jobs::UserEmail.new.execute(type: :user_private_message, user_id: suspended.id, post_id: post.id)
|
2013-10-30 15:31:16 -04:00
|
|
|
end
|
|
|
|
|
2017-01-05 03:15:55 -05:00
|
|
|
it "does send an email for a pm from a staff user" do
|
2013-10-30 15:31:16 -04:00
|
|
|
pm_from_staff = Fabricate(:post, user: Fabricate(:moderator))
|
2013-11-07 13:53:32 -05:00
|
|
|
pm_from_staff.topic.topic_allowed_users.create!(user_id: suspended.id)
|
2017-01-05 03:15:55 -05:00
|
|
|
Email::Sender.any_instance.expects(:send)
|
|
|
|
Jobs::UserEmail.new.execute(type: :user_private_message, user_id: suspended.id, post_id: pm_from_staff.id)
|
2013-10-30 15:31:16 -04:00
|
|
|
end
|
|
|
|
end
|
2015-05-10 19:10:10 -04:00
|
|
|
|
|
|
|
context 'user is anonymous' do
|
2017-07-07 02:09:14 -04:00
|
|
|
before { SiteSetting.allow_anonymous_posting = true }
|
2015-05-10 19:10:10 -04:00
|
|
|
|
|
|
|
it "doesn't send email for a pm from a regular user" do
|
|
|
|
Email::Sender.any_instance.expects(:send).never
|
2017-01-05 03:15:55 -05:00
|
|
|
Jobs::UserEmail.new.execute(type: :user_private_message, user_id: anonymous.id, post_id: post.id)
|
2015-05-10 19:10:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't send email for a pm from a staff user" do
|
|
|
|
pm_from_staff = Fabricate(:post, user: Fabricate(:moderator))
|
|
|
|
pm_from_staff.topic.topic_allowed_users.create!(user_id: anonymous.id)
|
|
|
|
Email::Sender.any_instance.expects(:send).never
|
2017-01-05 03:15:55 -05:00
|
|
|
Jobs::UserEmail.new.execute(type: :user_private_message, user_id: anonymous.id, post_id: pm_from_staff.id)
|
2015-05-10 19:10:10 -04:00
|
|
|
end
|
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'notification' do
|
2013-06-10 12:02:04 -04:00
|
|
|
let(:post) { Fabricate(:post, user: user) }
|
2014-02-03 20:56:28 -05:00
|
|
|
let!(:notification) {
|
|
|
|
Fabricate(:notification,
|
|
|
|
user: user,
|
|
|
|
topic: post.topic,
|
|
|
|
post_number: post.post_number,
|
|
|
|
data: {
|
|
|
|
original_post_id: post.id
|
|
|
|
}.to_json
|
|
|
|
)
|
|
|
|
}
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
it "doesn't send the email if the notification has been seen" do
|
|
|
|
notification.update_column(:read, true)
|
2016-01-26 20:19:49 -05:00
|
|
|
message, err = Jobs::UserEmail.new.message_for_email(
|
|
|
|
user,
|
|
|
|
post,
|
|
|
|
:user_mentioned,
|
|
|
|
notification,
|
|
|
|
notification.notification_type,
|
|
|
|
notification.data_hash,
|
|
|
|
nil,
|
|
|
|
nil)
|
|
|
|
|
|
|
|
expect(message).to eq nil
|
|
|
|
expect(err.skipped_reason).to match(/notification.*already/)
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
2014-06-09 23:36:20 -04:00
|
|
|
it "does send the email if the notification has been seen but the user is set for email_always" do
|
2014-06-09 07:09:36 -04:00
|
|
|
Email::Sender.any_instance.expects(:send)
|
|
|
|
notification.update_column(:read, true)
|
2016-02-16 23:46:19 -05:00
|
|
|
user.user_option.update_column(:email_always, true)
|
2014-06-09 07:09:36 -04:00
|
|
|
Jobs::UserEmail.new.execute(type: :user_mentioned, user_id: user.id, notification_id: notification.id)
|
|
|
|
end
|
|
|
|
|
2016-08-03 12:29:38 -04:00
|
|
|
it "does send the email if the user is using daily mailing list mode" do
|
|
|
|
Email::Sender.any_instance.expects(:send)
|
|
|
|
user.user_option.update(mailing_list_mode: true, mailing_list_mode_frequency: 0)
|
|
|
|
|
|
|
|
Jobs::UserEmail.new.execute(type: :user_mentioned, user_id: user.id, notification_id: notification.id)
|
|
|
|
end
|
|
|
|
|
2017-05-03 04:03:43 -04:00
|
|
|
context 'max_emails_per_day_per_user limit is reached' do
|
|
|
|
before do
|
|
|
|
SiteSetting.max_emails_per_day_per_user = 2
|
2017-05-03 08:14:32 -04:00
|
|
|
2.times { Fabricate(:email_log, user: user, email_type: 'blah', to_address: user.email) }
|
2017-05-03 04:03:43 -04:00
|
|
|
end
|
2016-03-23 00:08:34 -04:00
|
|
|
|
2017-05-03 04:03:43 -04:00
|
|
|
it "does not send notification if limit is reached" do
|
|
|
|
Jobs::UserEmail.new.execute(type: :user_mentioned, user_id: user.id, notification_id: notification.id, post_id: post.id)
|
|
|
|
expect(EmailLog.where(user_id: user.id, skipped: true).count).to eq(1)
|
|
|
|
end
|
2016-03-23 00:08:34 -04:00
|
|
|
|
2017-05-03 07:36:01 -04:00
|
|
|
it "sends critical email" do
|
2017-05-03 04:03:43 -04:00
|
|
|
Jobs::UserEmail.new.execute(type: :forgot_password, user_id: user.id, notification_id: notification.id, post_id: post.id)
|
|
|
|
expect(EmailLog.where(user_id: user.id, skipped: true).count).to eq(0)
|
|
|
|
end
|
2016-03-23 00:08:34 -04:00
|
|
|
end
|
|
|
|
|
2016-05-02 17:15:32 -04:00
|
|
|
it "does not send notification if bounce threshold is reached" do
|
|
|
|
user.user_stat.update(bounce_score: SiteSetting.bounce_score_threshold)
|
|
|
|
Jobs::UserEmail.new.execute(type: :user_mentioned, user_id: user.id, notification_id: notification.id, post_id: post.id)
|
|
|
|
expect(EmailLog.where(user_id: user.id, skipped: true).count).to eq(1)
|
|
|
|
end
|
|
|
|
|
2016-08-03 12:29:38 -04:00
|
|
|
it "doesn't send the mail if the user is using individual mailing list mode" do
|
2016-02-03 13:27:58 -05:00
|
|
|
Email::Sender.any_instance.expects(:send).never
|
2016-08-03 12:29:38 -04:00
|
|
|
user.user_option.update(mailing_list_mode: true, mailing_list_mode_frequency: 1)
|
2016-02-05 14:07:30 -05:00
|
|
|
# sometimes, we pass the notification_id
|
2016-02-03 13:27:58 -05:00
|
|
|
Jobs::UserEmail.new.execute(type: :user_mentioned, user_id: user.id, notification_id: notification.id, post_id: post.id)
|
2016-02-05 14:07:30 -05:00
|
|
|
# other times, we only pass the type of notification
|
|
|
|
Jobs::UserEmail.new.execute(type: :user_mentioned, user_id: user.id, notification_type: "posted", post_id: post.id)
|
2016-02-24 01:30:28 -05:00
|
|
|
# When post is nil
|
|
|
|
Jobs::UserEmail.new.execute(type: :user_mentioned, user_id: user.id, notification_type: "posted")
|
|
|
|
# When post does not have a topic
|
|
|
|
post = Fabricate(:post)
|
|
|
|
post.topic.destroy
|
2016-03-23 00:08:34 -04:00
|
|
|
Jobs::UserEmail.new.execute(type: :user_mentioned, user_id: user.id, notification_type: "posted", post_id: post.id)
|
2016-02-03 13:27:58 -05:00
|
|
|
end
|
|
|
|
|
2016-10-05 19:28:58 -04:00
|
|
|
it "doesn't send the mail if the user is using individual mailing list mode with no echo" do
|
|
|
|
Email::Sender.any_instance.expects(:send).never
|
|
|
|
user.user_option.update(mailing_list_mode: true, mailing_list_mode_frequency: 2)
|
|
|
|
# sometimes, we pass the notification_id
|
|
|
|
Jobs::UserEmail.new.execute(type: :user_mentioned, user_id: user.id, notification_id: notification.id, post_id: post.id)
|
|
|
|
# other times, we only pass the type of notification
|
|
|
|
Jobs::UserEmail.new.execute(type: :user_mentioned, user_id: user.id, notification_type: "posted", post_id: post.id)
|
|
|
|
# When post is nil
|
|
|
|
Jobs::UserEmail.new.execute(type: :user_mentioned, user_id: user.id, notification_type: "posted")
|
|
|
|
# When post does not have a topic
|
|
|
|
post = Fabricate(:post)
|
|
|
|
post.topic.destroy
|
|
|
|
Jobs::UserEmail.new.execute(type: :user_mentioned, user_id: user.id, notification_type: "posted", post_id: post.id)
|
|
|
|
end
|
|
|
|
|
2013-06-10 12:02:04 -04:00
|
|
|
it "doesn't send the email if the post has been user deleted" do
|
2013-06-10 15:33:37 -04:00
|
|
|
Email::Sender.any_instance.expects(:send).never
|
2013-06-10 12:02:04 -04:00
|
|
|
post.update_column(:user_deleted, true)
|
2016-02-03 13:27:58 -05:00
|
|
|
Jobs::UserEmail.new.execute(type: :user_mentioned, user_id: user.id, notification_id: notification.id, post_id: post.id)
|
2013-06-10 12:02:04 -04:00
|
|
|
end
|
|
|
|
|
2013-11-07 13:53:32 -05:00
|
|
|
context 'user is suspended' do
|
2013-10-30 15:31:16 -04:00
|
|
|
it "doesn't send email for a pm from a regular user" do
|
2017-07-27 21:20:09 -04:00
|
|
|
msg, err = Jobs::UserEmail.new.message_for_email(
|
2016-01-26 20:19:49 -05:00
|
|
|
suspended,
|
|
|
|
Fabricate.build(:post),
|
|
|
|
:user_private_message,
|
|
|
|
notification
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(msg).to eq(nil)
|
|
|
|
expect(err).not_to eq(nil)
|
2013-10-30 15:31:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'pm from staff' do
|
|
|
|
before do
|
|
|
|
@pm_from_staff = Fabricate(:post, user: Fabricate(:moderator))
|
2013-11-07 13:53:32 -05:00
|
|
|
@pm_from_staff.topic.topic_allowed_users.create!(user_id: suspended.id)
|
2014-02-03 20:56:28 -05:00
|
|
|
@pm_notification = Fabricate(:notification,
|
|
|
|
user: suspended,
|
|
|
|
topic: @pm_from_staff.topic,
|
|
|
|
post_number: @pm_from_staff.post_number,
|
|
|
|
data: { original_post_id: @pm_from_staff.id }.to_json
|
|
|
|
)
|
2013-10-30 15:31:16 -04:00
|
|
|
end
|
|
|
|
|
2016-01-26 20:19:49 -05:00
|
|
|
let :sent_message do
|
|
|
|
Jobs::UserEmail.new.message_for_email(
|
|
|
|
suspended,
|
|
|
|
@pm_from_staff,
|
|
|
|
:user_private_message,
|
|
|
|
@pm_notification
|
|
|
|
)
|
|
|
|
end
|
2013-10-30 15:31:16 -04:00
|
|
|
|
|
|
|
it "sends an email" do
|
2017-07-27 21:20:09 -04:00
|
|
|
msg, err = sent_message
|
2016-01-26 20:19:49 -05:00
|
|
|
expect(msg).not_to be(nil)
|
|
|
|
expect(err).to be(nil)
|
2013-10-30 15:31:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "sends an email even if user was last seen recently" do
|
2013-11-07 13:53:32 -05:00
|
|
|
suspended.update_column(:last_seen_at, 1.minute.ago)
|
2016-01-26 20:19:49 -05:00
|
|
|
|
2017-07-27 21:20:09 -04:00
|
|
|
msg, err = sent_message
|
2016-01-26 20:19:49 -05:00
|
|
|
expect(msg).not_to be(nil)
|
|
|
|
expect(err).to be(nil)
|
2013-10-30 15:31:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-05-10 19:10:10 -04:00
|
|
|
|
|
|
|
context 'user is anonymous' do
|
2017-07-07 02:09:14 -04:00
|
|
|
before { SiteSetting.allow_anonymous_posting = true }
|
2015-05-10 19:10:10 -04:00
|
|
|
|
|
|
|
it "doesn't send email for a pm from a regular user" do
|
|
|
|
Email::Sender.any_instance.expects(:send).never
|
|
|
|
Jobs::UserEmail.new.execute(type: :user_private_message, user_id: anonymous.id, notification_id: notification.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't send email for a pm from staff" do
|
|
|
|
pm_from_staff = Fabricate(:post, user: Fabricate(:moderator))
|
|
|
|
pm_from_staff.topic.topic_allowed_users.create!(user_id: anonymous.id)
|
|
|
|
pm_notification = Fabricate(:notification,
|
|
|
|
user: anonymous,
|
|
|
|
topic: pm_from_staff.topic,
|
|
|
|
post_number: pm_from_staff.post_number,
|
|
|
|
data: { original_post_id: pm_from_staff.id }.to_json
|
|
|
|
)
|
|
|
|
Email::Sender.any_instance.expects(:send).never
|
|
|
|
Jobs::UserEmail.new.execute(type: :user_private_message, user_id: anonymous.id, notification_id: pm_notification.id)
|
|
|
|
end
|
|
|
|
end
|
2013-02-25 11:42:20 -05:00
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|