2015-08-06 12:03:27 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe AbuseReport, type: :model do
|
2016-03-07 12:46:37 +00:00
|
|
|
subject { create(:abuse_report) }
|
2017-02-21 07:20:05 +00:00
|
|
|
let(:user) { create(:admin) }
|
2015-08-06 12:03:27 +00:00
|
|
|
|
|
|
|
it { expect(subject).to be_valid }
|
2015-09-29 16:08:55 +00:00
|
|
|
|
|
|
|
describe 'associations' do
|
|
|
|
it { is_expected.to belong_to(:reporter).class_name('User') }
|
|
|
|
it { is_expected.to belong_to(:user) }
|
2016-10-06 21:17:11 +00:00
|
|
|
|
|
|
|
it "aliases reporter to author" do
|
|
|
|
expect(subject.author).to be(subject.reporter)
|
|
|
|
end
|
2015-09-29 16:08:55 +00: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 21:25:35 +00:00
|
|
|
it { is_expected.to validate_uniqueness_of(:user_id).with_message('has already been reported') }
|
2015-09-29 16:08:55 +00:00
|
|
|
end
|
2016-01-04 23:59:42 +00:00
|
|
|
|
2016-01-13 01:48:16 +00:00
|
|
|
describe '#remove_user' do
|
|
|
|
it 'blocks the user' do
|
2016-03-12 12:11:30 +00:00
|
|
|
expect { subject.remove_user(deleted_by: user) }.to change { subject.user.blocked? }.to(true)
|
2016-01-13 01:48:16 +00:00
|
|
|
end
|
|
|
|
|
2016-03-07 12:46:37 +00:00
|
|
|
it 'lets a worker delete the user' do
|
2017-06-02 13:18:24 +00:00
|
|
|
expect(DeleteUserWorker).to receive(:perform_async).with(user.id, subject.user.id, hard_delete: true)
|
2016-01-13 01:48:16 +00:00
|
|
|
|
2016-03-12 12:11:30 +00:00
|
|
|
subject.remove_user(deleted_by: user)
|
2016-01-13 01:48:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-04 23:59:42 +00:00
|
|
|
describe '#notify' do
|
|
|
|
it 'delivers' do
|
2017-06-21 13:48:12 +00:00
|
|
|
expect(AbuseReportMailer).to receive(:notify).with(subject.id)
|
|
|
|
.and_return(spy)
|
2016-01-04 23:59:42 +00: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 12:03:27 +00:00
|
|
|
end
|