Commit 795ba752 authored by charlieablett's avatar charlieablett

Rename `HamService.mark_as_ham!` to execute

parent becf7b82
......@@ -24,7 +24,7 @@ class Admin::SpamLogsController < Admin::ApplicationController
def mark_as_ham
spam_log = SpamLog.find(params[:id])
if Spam::HamService.new(spam_log).mark_as_ham!
if Spam::HamService.new(spam_log).execute
redirect_to admin_spam_logs_path, notice: _('Spam log successfully submitted as ham.')
else
redirect_to admin_spam_logs_path, alert: _('Error with Akismet. Please check the logs for more info.')
......
......@@ -8,7 +8,7 @@ module Spam
@spam_log = spam_log
end
def mark_as_ham!
def execute
if akismet.submit_ham
spam_log.update_attribute(:submitted_as_ham, true)
else
......
......@@ -13,18 +13,18 @@ describe Spam::HamService do
allow(Spam::AkismetService).to receive(:new).and_return fake_akismet_service
end
describe '#mark_as_ham!' do
describe '#execute' do
context 'AkismetService returns false (Akismet cannot be reached, etc)' do
before do
allow(fake_akismet_service).to receive(:submit_ham).and_return false
end
it 'returns false' do
expect(subject.mark_as_ham!).to be_falsey
expect(subject.execute).to be_falsey
end
it 'does not update the record' do
expect { subject.mark_as_ham! }.not_to change { spam_log.submitted_as_ham }
expect { subject.execute }.not_to change { spam_log.submitted_as_ham }
end
context 'if spam log record has already been marked as spam' do
......@@ -33,7 +33,7 @@ describe Spam::HamService do
end
it 'does not update the record' do
expect { subject.mark_as_ham! }.not_to change { spam_log.submitted_as_ham }
expect { subject.execute }.not_to change { spam_log.submitted_as_ham }
end
end
end
......@@ -45,11 +45,11 @@ describe Spam::HamService do
end
it 'returns true' do
expect(subject.mark_as_ham!).to be_truthy
expect(subject.execute).to be_truthy
end
it 'updates the record' do
expect { subject.mark_as_ham! }.to change { spam_log.submitted_as_ham }.from(false).to(true)
expect { subject.execute }.to change { spam_log.submitted_as_ham }.from(false).to(true)
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