Commit 0546f692 authored by charlieablett's avatar charlieablett

Modify SpamService initializer

Use named parameters for clarity.
parent 7c15fffd
...@@ -11,7 +11,7 @@ module SpammableActions ...@@ -11,7 +11,7 @@ module SpammableActions
end end
def mark_as_spam def mark_as_spam
if SpamService.new(spammable).mark_as_spam! if SpamService.new(spammable: spammable).mark_as_spam!
redirect_to spammable_path, notice: _("%{spammable_titlecase} was submitted to Akismet successfully.") % { spammable_titlecase: spammable.spammable_entity_type.titlecase } redirect_to spammable_path, notice: _("%{spammable_titlecase} was submitted to Akismet successfully.") % { spammable_titlecase: spammable.spammable_entity_type.titlecase }
else else
redirect_to spammable_path, alert: _('Error with Akismet. Please check the logs for more info.') redirect_to spammable_path, alert: _('Error with Akismet. Please check the logs for more info.')
......
...@@ -24,7 +24,7 @@ module Mutations ...@@ -24,7 +24,7 @@ module Mutations
private private
def mark_as_spam(snippet) def mark_as_spam(snippet)
SpamService.new(snippet).mark_as_spam! SpamService.new(spammable: snippet).mark_as_spam!
end end
def authorized_resource?(snippet) def authorized_resource?(snippet)
......
...@@ -24,7 +24,7 @@ module SpamCheckMethods ...@@ -24,7 +24,7 @@ module SpamCheckMethods
# rubocop:disable Gitlab/ModuleWithInstanceVariables # rubocop:disable Gitlab/ModuleWithInstanceVariables
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def spam_check(spammable, user) def spam_check(spammable, user)
spam_service = SpamService.new(spammable, @request) spam_service = SpamService.new(spammable: spammable, request: @request)
spam_service.when_recaptcha_verified(@recaptcha_verified, @api) do spam_service.when_recaptcha_verified(@recaptcha_verified, @api) do
user.spam_logs.find_by(id: @spam_log_id)&.update!(recaptcha_verified: true) user.spam_logs.find_by(id: @spam_log_id)&.update!(recaptcha_verified: true)
......
...@@ -4,7 +4,7 @@ class SpamService ...@@ -4,7 +4,7 @@ class SpamService
attr_accessor :spammable, :request, :options attr_accessor :spammable, :request, :options
attr_reader :spam_log attr_reader :spam_log
def initialize(spammable, request = nil) def initialize(spammable:, request: nil)
@spammable = spammable @spammable = spammable
@request = request @request = request
@options = {} @options = {}
......
...@@ -5,7 +5,7 @@ require 'spec_helper' ...@@ -5,7 +5,7 @@ require 'spec_helper'
describe SpamService do describe SpamService do
describe '#when_recaptcha_verified' do describe '#when_recaptcha_verified' do
def check_spam(issue, request, recaptcha_verified) def check_spam(issue, request, recaptcha_verified)
described_class.new(issue, request).when_recaptcha_verified(recaptcha_verified) do described_class.new(spammable: issue, request: request).when_recaptcha_verified(recaptcha_verified) do
'yielded' 'yielded'
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