Commit d24f6917 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'cablett-ham-service-execute' into 'master'

Rename `HamService.mark_as_ham!` to `execute`

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