mirror of
https://github.com/discourse/discourse.git
synced 2025-06-03 19:39:30 +08:00
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:

committed by
Guo Xiang Tan

parent
48d0465f72
commit
a9d5ffbe3d
@ -137,32 +137,40 @@ describe Admin::EmailController do
|
||||
let(:eviltrout) { Fabricate(:evil_trout) }
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
|
||||
it 'does not sends mail to anyone when setting is "yes"' do
|
||||
it 'bypasses disable when setting is "yes"' do
|
||||
SiteSetting.disable_emails = 'yes'
|
||||
|
||||
post "/admin/email/test.json", params: { email_address: admin.email }
|
||||
|
||||
incoming = JSON.parse(response.body)
|
||||
expect(incoming['sent_test_email_message']).to eq(I18n.t("admin.email.sent_test_disabled"))
|
||||
end
|
||||
expect(ActionMailer::Base.deliveries.first.to).to contain_exactly(
|
||||
admin.email
|
||||
)
|
||||
|
||||
it 'sends mail to staff only when setting is "non-staff"' do
|
||||
SiteSetting.disable_emails = 'non-staff'
|
||||
|
||||
post "/admin/email/test.json", params: { email_address: admin.email }
|
||||
incoming = JSON.parse(response.body)
|
||||
expect(incoming['sent_test_email_message']).to eq(I18n.t("admin.email.sent_test"))
|
||||
|
||||
post "/admin/email/test.json", params: { email_address: eviltrout.email }
|
||||
incoming = JSON.parse(response.body)
|
||||
expect(incoming['sent_test_email_message']).to eq(I18n.t("admin.email.sent_test_disabled_for_non_staff"))
|
||||
end
|
||||
|
||||
it 'sends mail to everyone when setting is "no"' do
|
||||
it 'bypasses disable when setting is "non-staff"' do
|
||||
SiteSetting.disable_emails = 'non-staff'
|
||||
|
||||
post "/admin/email/test.json", params: { email_address: eviltrout.email }
|
||||
|
||||
expect(ActionMailer::Base.deliveries.first.to).to contain_exactly(
|
||||
eviltrout.email
|
||||
)
|
||||
|
||||
incoming = JSON.parse(response.body)
|
||||
expect(incoming['sent_test_email_message']).to eq(I18n.t("admin.email.sent_test"))
|
||||
end
|
||||
|
||||
it 'works when setting is "no"' do
|
||||
SiteSetting.disable_emails = 'no'
|
||||
|
||||
post "/admin/email/test.json", params: { email_address: eviltrout.email }
|
||||
|
||||
expect(ActionMailer::Base.deliveries.first.to).to contain_exactly(
|
||||
eviltrout.email
|
||||
)
|
||||
|
||||
incoming = JSON.parse(response.body)
|
||||
expect(incoming['sent_test_email_message']).to eq(I18n.t("admin.email.sent_test"))
|
||||
end
|
||||
|
Reference in New Issue
Block a user