FIX: Prevent critical emails bypassing disable, and improve email test logic

- The test_email job is removed, because it was always being run synchronously (not in sidekiq)
- 34b29f62 added a bypass for critical emails, to match the spec. This removes the bypass, and removes the spec.
- This adapts the specs for 72ffabf6, so that they check for emails being sent
- This reimplements c2797921, allowing test emails to be sent even when emails are disabled
This commit is contained in:
David Taylor
2019-03-21 21:57:09 +00:00
committed by Guo Xiang Tan
parent 48d0465f72
commit a9d5ffbe3d
9 changed files with 46 additions and 91 deletions

View File

@ -12,15 +12,24 @@ describe Email::Sender do
before { SiteSetting.disable_emails = "yes" }
it "doesn't deliver mail when mails are disabled" do
Mail::Message.any_instance.expects(:deliver_now).never
message = Mail::Message.new(to: moderator.email , body: "hello")
expect(Email::Sender.new(message, :hello).send).to eq(nil)
message = UserNotifications.email_login(moderator)
Email::Sender.new(message, :email_login).send
expect(ActionMailer::Base.deliveries).to eq([])
end
it "delivers mail when mails are disabled but the email_type is admin_login" do
Mail::Message.any_instance.expects(:deliver_now).once
message = Mail::Message.new(to: moderator.email , body: "hello")
message = UserNotifications.admin_login(moderator)
Email::Sender.new(message, :admin_login).send
expect(ActionMailer::Base.deliveries.first.to).to eq([moderator.email])
end
it "delivers mail when mails are disabled but the email_type is test_message" do
message = TestMailer.send_test(moderator.email)
Email::Sender.new(message, :test_message).send
expect(ActionMailer::Base.deliveries.first.to).to eq([moderator.email])
end
end