Commit d1b49397 authored by charlieablett's avatar charlieablett

Rename 'spammable' to 'target'

Only renames instances within the classes that directly
use AkismetMethods, but not the external interfaces.
parent e68921ae
...@@ -11,7 +11,7 @@ module SpammableActions ...@@ -11,7 +11,7 @@ module SpammableActions
end end
def mark_as_spam def mark_as_spam
if Spam::MarkAsSpamService.new(spammable: spammable).execute if Spam::MarkAsSpamService.new(target: spammable).execute
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.')
......
# frozen_string_literal: true # frozen_string_literal: true
module AkismetMethods module AkismetMethods
def spammable_owner def target_owner
@user ||= User.find(spammable.author_id) @user ||= User.find(target.author_id)
end end
def akismet def akismet
@akismet ||= Spam::AkismetService.new( @akismet ||= Spam::AkismetService.new(
spammable_owner.name, target_owner.name,
spammable_owner.email, target_owner.email,
spammable.try(:spammable_text) || spammable&.text, target.try(:spammable_text) || target&.text,
options options
) )
end end
......
...@@ -23,6 +23,6 @@ module Spam ...@@ -23,6 +23,6 @@ module Spam
end end
end end
alias_method :spammable, :spam_log alias_method :target, :spam_log
end end
end end
...@@ -4,21 +4,21 @@ module Spam ...@@ -4,21 +4,21 @@ module Spam
class MarkAsSpamService class MarkAsSpamService
include ::AkismetMethods include ::AkismetMethods
attr_accessor :spammable, :options attr_accessor :target, :options
def initialize(spammable:) def initialize(target:)
@spammable = spammable @target = target
@options = {} @options = {}
@options[:ip_address] = @spammable.ip_address @options[:ip_address] = @target.ip_address
@options[:user_agent] = @spammable.user_agent @options[:user_agent] = @target.user_agent
end end
def execute def execute
return unless spammable.submittable_as_spam? return unless target.submittable_as_spam?
return unless akismet.submit_spam return unless akismet.submit_spam
spammable.user_agent_detail.update_attribute(:submitted, true) target.user_agent_detail.update_attribute(:submitted, true)
end end
end end
end end
...@@ -4,11 +4,11 @@ module Spam ...@@ -4,11 +4,11 @@ module Spam
class SpamCheckService class SpamCheckService
include AkismetMethods include AkismetMethods
attr_accessor :spammable, :request, :options attr_accessor :target, :request, :options
attr_reader :spam_log attr_reader :spam_log
def initialize(spammable:, request:) def initialize(spammable:, request:)
@spammable = spammable @target = spammable
@request = request @request = request
@options = {} @options = {}
...@@ -17,8 +17,8 @@ module Spam ...@@ -17,8 +17,8 @@ module Spam
@options[:user_agent] = @request.env['HTTP_USER_AGENT'] @options[:user_agent] = @request.env['HTTP_USER_AGENT']
@options[:referrer] = @request.env['HTTP_REFERRER'] @options[:referrer] = @request.env['HTTP_REFERRER']
else else
@options[:ip_address] = @spammable.ip_address @options[:ip_address] = @target.ip_address
@options[:user_agent] = @spammable.user_agent @options[:user_agent] = @target.user_agent
end end
end end
...@@ -31,8 +31,8 @@ module Spam ...@@ -31,8 +31,8 @@ module Spam
# Otherwise, it goes to Akismet for spam check. # Otherwise, it goes to Akismet for spam check.
# If so, it assigns spammable object as "spam" and creates a SpamLog record. # If so, it assigns spammable object as "spam" and creates a SpamLog record.
possible_spam = check(api) possible_spam = check(api)
spammable.spam = possible_spam unless spammable.allow_possible_spam? target.spam = possible_spam unless target.allow_possible_spam?
spammable.spam_log = spam_log target.spam_log = spam_log
end end
end end
...@@ -48,18 +48,18 @@ module Spam ...@@ -48,18 +48,18 @@ module Spam
end end
def check_for_spam? def check_for_spam?
spammable.check_for_spam? target.check_for_spam?
end end
def create_spam_log(api) def create_spam_log(api)
@spam_log = SpamLog.create!( @spam_log = SpamLog.create!(
{ {
user_id: spammable.author_id, user_id: target.author_id,
title: spammable.spam_title, title: target.spam_title,
description: spammable.spam_description, description: target.spam_description,
source_ip: options[:ip_address], source_ip: options[:ip_address],
user_agent: options[:user_agent], user_agent: options[:user_agent],
noteable_type: spammable.class.to_s, noteable_type: target.class.to_s,
via_api: api via_api: api
} }
) )
......
...@@ -740,16 +740,16 @@ describe Projects::IssuesController do ...@@ -740,16 +740,16 @@ describe Projects::IssuesController do
.to log_spam(title: 'Spam title', noteable_type: 'Issue') .to log_spam(title: 'Spam title', noteable_type: 'Issue')
end end
it 'renders recaptcha_html json response' do context 'renders properly' do
update_issue render_views
expect(json_response).to have_key('recaptcha_html')
end
it 'returns 200 status' do it 'renders recaptcha_html json response' do
update_issue update_issue
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to have_key('recaptcha_html')
expect(json_response['recaptcha_html']).not_to be_empty
end
end end
end end
......
...@@ -7,7 +7,7 @@ describe Spam::MarkAsSpamService do ...@@ -7,7 +7,7 @@ describe Spam::MarkAsSpamService do
let(:spammable) { build(:issue, user_agent_detail: user_agent_detail) } let(:spammable) { build(:issue, user_agent_detail: user_agent_detail) }
let(:fake_akismet_service) { double(:akismet_service, submit_spam: true) } let(:fake_akismet_service) { double(:akismet_service, submit_spam: true) }
subject { described_class.new(spammable: spammable) } subject { described_class.new(target: spammable) }
describe '#execute' do describe '#execute' do
before do before do
......
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