Commit 98c9b44f authored by charlieablett's avatar charlieablett

Apply reviewer feedback

- Remove unneeded method
- Tweak test wording
- Use `execute` for service method
parent ff2ad442
......@@ -11,7 +11,7 @@ module SpammableActions
end
def mark_as_spam
if Spam::MarkAsSpamService.new(spammable: spammable).mark_as_spam!
if Spam::MarkAsSpamService.new(spammable: spammable).execute
redirect_to spammable_path, notice: _("%{spammable_titlecase} was submitted to Akismet successfully.") % { spammable_titlecase: spammable.spammable_entity_type.titlecase }
else
redirect_to spammable_path, alert: _('Error with Akismet. Please check the logs for more info.')
......
......@@ -24,7 +24,7 @@ module Mutations
private
def mark_as_spam(snippet)
Spam::MarkAsSpamService.new(spammable: snippet).mark_as_spam!
Spam::MarkAsSpamService.new(spammable: snippet).execute
end
def authorized_resource?(snippet)
......
......@@ -14,14 +14,11 @@ module Spam
@options[:user_agent] = @spammable.user_agent
end
def mark_as_spam!
return false unless spammable.submittable_as_spam?
def execute
return unless spammable.submittable_as_spam?
return unless akismet.submit_spam
if akismet.submit_spam
spammable.user_agent_detail.update_attribute(:submitted, true)
else
false
end
spammable.user_agent_detail.update_attribute(:submitted, true)
end
end
end
......@@ -46,15 +46,6 @@ class SpamService
true
end
def akismet
@akismet ||= AkismetService.new(
spammable_owner.name,
spammable_owner.email,
spammable.spammable_text,
options
)
end
def check_for_spam?
spammable.check_for_spam?
end
......
......@@ -53,7 +53,7 @@ describe 'Mark snippet as spam' do
it 'marks snippet as spam' do
expect_next_instance_of(Spam::MarkAsSpamService) do |instance|
expect(instance).to receive(:mark_as_spam!)
expect(instance).to receive(:execute)
end
post_graphql_mutation(mutation, current_user: current_user)
......
......@@ -9,42 +9,42 @@ describe Spam::MarkAsSpamService do
subject { described_class.new(spammable: spammable) }
describe '#mark_as_spam!' do
describe '#execute' do
before do
allow(subject).to receive(:akismet).and_return(fake_akismet_service)
end
context 'the spammable is not submittable' do
context 'when the spammable object is not submittable' do
before do
allow(spammable).to receive(:submittable_as_spam?).and_return false
end
it 'does not submit as spam' do
expect(subject.mark_as_spam!).to be_falsey
expect(subject.execute).to be_falsey
end
end
context 'the spam is submitted successfully' do
context 'spam is submitted successfully' do
before do
allow(spammable).to receive(:submittable_as_spam?).and_return true
allow(fake_akismet_service).to receive(:submit_spam).and_return true
end
it 'submits as spam' do
expect(subject.mark_as_spam!).to be_truthy
expect(subject.execute).to be_truthy
end
it "updates the spammable object's user agent detail as being submitted as spam" do
expect(user_agent_detail).to receive(:update_attribute)
subject.mark_as_spam!
subject.execute
end
context 'if Akismet does not consider it spam' do
it "does not update the spammable object as spam" do
context 'when Akismet does not consider it spam' do
it 'does not update the spammable object as spam' do
allow(fake_akismet_service).to receive(:submit_spam).and_return false
expect(subject.mark_as_spam!).to be_falsey
expect(subject.execute).to be_falsey
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment