2015-08-06 08:03:27 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2017-09-05 03:37:06 -04:00
|
|
|
describe AbuseReport do
|
|
|
|
set(:report) { create(:abuse_report) }
|
|
|
|
set(:user) { create(:admin) }
|
|
|
|
subject { report }
|
2015-08-06 08:03:27 -04:00
|
|
|
|
|
|
|
it { expect(subject).to be_valid }
|
2015-09-29 12:08:55 -04:00
|
|
|
|
|
|
|
describe 'associations' do
|
|
|
|
it { is_expected.to belong_to(:reporter).class_name('User') }
|
|
|
|
it { is_expected.to belong_to(:user) }
|
2016-10-06 17:17:11 -04:00
|
|
|
|
|
|
|
it "aliases reporter to author" do
|
|
|
|
expect(subject.author).to be(subject.reporter)
|
|
|
|
end
|
2015-09-29 12:08:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'validations' do
|
|
|
|
it { is_expected.to validate_presence_of(:reporter) }
|
|
|
|
it { is_expected.to validate_presence_of(:user) }
|
|
|
|
it { is_expected.to validate_presence_of(:message) }
|
2016-01-16 16:25:35 -05:00
|
|
|
it { is_expected.to validate_uniqueness_of(:user_id).with_message('has already been reported') }
|
2015-09-29 12:08:55 -04:00
|
|
|
end
|
2016-01-04 18:59:42 -05:00
|
|
|
|
2016-01-12 20:48:16 -05:00
|
|
|
describe '#remove_user' do
|
|
|
|
it 'blocks the user' do
|
2016-03-12 07:11:30 -05:00
|
|
|
expect { subject.remove_user(deleted_by: user) }.to change { subject.user.blocked? }.to(true)
|
2016-01-12 20:48:16 -05:00
|
|
|
end
|
|
|
|
|
2016-03-07 07:46:37 -05:00
|
|
|
it 'lets a worker delete the user' do
|
2017-06-02 09:18:24 -04:00
|
|
|
expect(DeleteUserWorker).to receive(:perform_async).with(user.id, subject.user.id, hard_delete: true)
|
2016-01-12 20:48:16 -05:00
|
|
|
|
2016-03-12 07:11:30 -05:00
|
|
|
subject.remove_user(deleted_by: user)
|
2016-01-12 20:48:16 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-04 18:59:42 -05:00
|
|
|
describe '#notify' do
|
|
|
|
it 'delivers' do
|
2017-06-21 09:48:12 -04:00
|
|
|
expect(AbuseReportMailer).to receive(:notify).with(subject.id)
|
|
|
|
.and_return(spy)
|
2016-01-04 18:59:42 -05:00
|
|
|
|
|
|
|
subject.notify
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns early when not persisted' do
|
|
|
|
report = build(:abuse_report)
|
|
|
|
|
|
|
|
expect(AbuseReportMailer).not_to receive(:notify)
|
|
|
|
|
|
|
|
report.notify
|
|
|
|
end
|
|
|
|
end
|
2015-08-06 08:03:27 -04:00
|
|
|
end
|