2020-01-16 07:08:32 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 11:08:50 -04:00
|
|
|
RSpec.describe Spam::MarkAsSpamService do
|
2020-01-16 07:08:32 -05:00
|
|
|
let(:user_agent_detail) { build(:user_agent_detail) }
|
2020-02-14 19:08:48 -05:00
|
|
|
let(:spammable) { build(:issue, user_agent_detail: user_agent_detail) }
|
2020-01-16 07:08:32 -05:00
|
|
|
let(:fake_akismet_service) { double(:akismet_service, submit_spam: true) }
|
|
|
|
|
2020-02-27 07:09:12 -05:00
|
|
|
subject { described_class.new(target: spammable) }
|
2020-01-16 07:08:32 -05:00
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
before do
|
|
|
|
allow(subject).to receive(:akismet).and_return(fake_akismet_service)
|
|
|
|
end
|
|
|
|
|
2020-02-14 19:08:48 -05:00
|
|
|
context 'when the spammable object is not submittable' do
|
2020-01-16 07:08:32 -05:00
|
|
|
before do
|
2020-02-14 19:08:48 -05:00
|
|
|
allow(spammable).to receive(:submittable_as_spam?).and_return false
|
2020-01-16 07:08:32 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not submit as spam' do
|
|
|
|
expect(subject.execute).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'spam is submitted successfully' do
|
|
|
|
before do
|
2020-02-14 19:08:48 -05:00
|
|
|
allow(spammable).to receive(:submittable_as_spam?).and_return true
|
2020-01-16 07:08:32 -05:00
|
|
|
allow(fake_akismet_service).to receive(:submit_spam).and_return true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'submits as spam' do
|
|
|
|
expect(subject.execute).to be_truthy
|
|
|
|
end
|
|
|
|
|
2020-02-14 19:08:48 -05:00
|
|
|
it "updates the spammable object's user agent detail as being submitted as spam" do
|
2020-01-16 07:08:32 -05:00
|
|
|
expect(user_agent_detail).to receive(:update_attribute)
|
|
|
|
|
|
|
|
subject.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when Akismet does not consider it spam' do
|
2020-02-14 19:08:48 -05:00
|
|
|
it 'does not update the spammable object as spam' do
|
2020-01-16 07:08:32 -05:00
|
|
|
allow(fake_akismet_service).to receive(:submit_spam).and_return false
|
|
|
|
|
|
|
|
expect(subject.execute).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|