2019-10-21 05:06:22 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-29 03:56:52 -04:00
|
|
|
require 'spec_helper'
|
2016-01-04 18:56:48 -05:00
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe AbuseReportMailer do
|
2016-01-04 18:56:48 -05:00
|
|
|
include EmailSpec::Matchers
|
|
|
|
|
|
|
|
describe '.notify' do
|
2019-02-20 10:18:15 -05:00
|
|
|
before do
|
2020-09-25 20:09:35 -04:00
|
|
|
stub_application_setting(abuse_notification_email: 'admin@example.com')
|
2019-02-20 10:18:15 -05:00
|
|
|
end
|
2016-01-04 18:56:48 -05:00
|
|
|
|
2019-02-20 10:18:15 -05:00
|
|
|
let(:report) { create(:abuse_report) }
|
|
|
|
|
|
|
|
subject { described_class.notify(report.id) }
|
2016-01-04 18:56:48 -05:00
|
|
|
|
2019-02-20 10:18:15 -05:00
|
|
|
it_behaves_like 'appearance header and footer enabled'
|
|
|
|
it_behaves_like 'appearance header and footer not enabled'
|
2016-01-04 18:56:48 -05:00
|
|
|
|
2020-09-25 20:09:35 -04:00
|
|
|
context 'with abuse_notification_email set' do
|
|
|
|
it 'sends to the abuse_notification_email' do
|
2019-02-20 10:18:15 -05:00
|
|
|
is_expected.to deliver_to 'admin@example.com'
|
2016-01-04 18:56:48 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes the user in the subject' do
|
2019-02-20 10:18:15 -05:00
|
|
|
is_expected.to have_subject "#{report.user.name} (#{report.user.username}) was reported for abuse"
|
2016-01-04 18:56:48 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-25 20:09:35 -04:00
|
|
|
context 'with no abuse_notification_email set' do
|
2016-01-04 18:56:48 -05:00
|
|
|
it 'returns early' do
|
2020-09-25 20:09:35 -04:00
|
|
|
stub_application_setting(abuse_notification_email: nil)
|
2016-01-04 18:56:48 -05:00
|
|
|
|
2017-06-21 09:48:12 -04:00
|
|
|
expect { described_class.notify(spy).deliver_now }
|
|
|
|
.not_to change { ActionMailer::Base.deliveries.count }
|
2016-01-04 18:56:48 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|