diff --git a/app/controllers/admin/spam_logs_controller.rb b/app/controllers/admin/spam_logs_controller.rb index a317f4086c6e6300815d7e3418df1ad310b1e714..689e502a22191717c3357c7dce18bd35dddafc91 100644 --- a/app/controllers/admin/spam_logs_controller.rb +++ b/app/controllers/admin/spam_logs_controller.rb @@ -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.') diff --git a/app/services/spam/ham_service.rb b/app/services/spam/ham_service.rb index f367eb8c21eaeede12d68bbfb59d6cac646d48c8..e8444ba8f93545d681089bb51265ecbb36d9e781 100644 --- a/app/services/spam/ham_service.rb +++ b/app/services/spam/ham_service.rb @@ -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 diff --git a/spec/services/spam/ham_service_spec.rb b/spec/services/spam/ham_service_spec.rb index 9e60078edfe8f691b39a7b90e32200e52ca9f89b..9848f48def217c08643bb90147173fdd3e9e3386 100644 --- a/spec/services/spam/ham_service_spec.rb +++ b/spec/services/spam/ham_service_spec.rb @@ -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