2016-01-14 18:37:52 +05:30
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe AbuseReportMailer do
|
|
|
|
include EmailSpec::Matchers
|
|
|
|
|
|
|
|
describe '.notify' do
|
2019-05-30 16:15:17 +05:30
|
|
|
context 'with admin_notification_email set' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(admin_notification_email: 'admin@example.com')
|
|
|
|
end
|
2019-05-18 00:54:41 +05:30
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
it 'sends to the admin_notification_email' do
|
|
|
|
report = create(:abuse_report)
|
2016-01-14 18:37:52 +05:30
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
mail = described_class.notify(report.id)
|
2016-01-14 18:37:52 +05:30
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
expect(mail).to deliver_to 'admin@example.com'
|
2016-01-14 18:37:52 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes the user in the subject' do
|
2019-05-30 16:15:17 +05:30
|
|
|
report = create(:abuse_report)
|
|
|
|
|
|
|
|
mail = described_class.notify(report.id)
|
|
|
|
|
|
|
|
expect(mail).to have_subject "#{report.user.name} (#{report.user.username}) was reported for abuse"
|
2016-01-14 18:37:52 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with no admin_notification_email set' do
|
|
|
|
it 'returns early' do
|
|
|
|
stub_application_setting(admin_notification_email: nil)
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect { described_class.notify(spy).deliver_now }
|
|
|
|
.not_to change { ActionMailer::Base.deliveries.count }
|
2016-01-14 18:37:52 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|