Renaming AwardedEmojiFinder to a Service

This finder class acts more as a service, as it only returns mapped
data.

Renaming this class allows us to create a new AwardEmojiFinder without
the ambiguity of there being two similarly-named finders.

https://gitlab.com/gitlab-org/gitlab-ce/issues/63372
This commit is contained in:
Luke Duncalfe 2019-06-18 17:15:53 +12:00
parent 80c57bf6d1
commit 330cbddec3
4 changed files with 25 additions and 23 deletions

View File

@ -36,7 +36,7 @@ class AutocompleteController < ApplicationController
end
def award_emojis
render json: AwardedEmojiFinder.new(current_user).execute
render json: AwardEmojis::CollectUserEmojiService.new(current_user).execute
end
def merge_request_target_branches

View File

@ -1,21 +0,0 @@
# frozen_string_literal: true
# Class for retrieving information about emoji awarded _by_ a particular user.
class AwardedEmojiFinder
attr_reader :current_user
# current_user - The User to generate the data for.
def initialize(current_user = nil)
@current_user = current_user
end
def execute
return [] unless current_user
# We want the resulting data set to be an Array containing the emoji names
# in descending order, based on how often they were awarded.
AwardEmoji
.award_counts_for_user(current_user)
.map { |name, _| { name: name } }
end
end

View File

@ -0,0 +1,23 @@
# frozen_string_literal: true
# Class for retrieving information about emoji awarded _by_ a particular user.
module AwardEmojis
class CollectUserEmojiService
attr_reader :current_user
# current_user - The User to generate the data for.
def initialize(current_user = nil)
@current_user = current_user
end
def execute
return [] unless current_user
# We want the resulting data set to be an Array containing the emoji names
# in descending order, based on how often they were awarded.
AwardEmoji
.award_counts_for_user(current_user)
.map { |name, _| { name: name } }
end
end
end

View File

@ -2,7 +2,7 @@
require 'spec_helper'
describe AwardedEmojiFinder do
describe AwardEmojis::CollectUserEmojiService do
describe '#execute' do
it 'returns an Array containing the awarded emoji names' do
user = create(:user)