gitlab-org--gitlab-foss/lib/api/helpers/badges_helpers.rb
gfyoung 3836d69119 Enable frozen string in lib/api and lib/backup
Partially addresses #47424.

Had to make changes to spec files because
stubbing methods on frozen objects is a mess
in RSpec and leads to failures:

https://github.com/rspec/rspec-mocks/issues/1190
2018-09-29 21:04:50 -07:00

30 lines
766 B
Ruby

# frozen_string_literal: true
module API
module Helpers
module BadgesHelpers
include ::API::Helpers::MembersHelpers
def find_badge(source)
source.badges.find(params[:badge_id])
end
def present_badges(source, records, options = {})
entity_type = options[:with] || Entities::Badge
badge_params = badge_source_params(source).merge(with: entity_type)
present records, badge_params
end
def badge_source_params(source)
project = if source.is_a?(Project)
source
else
GroupProjectsFinder.new(group: source, current_user: current_user).execute.first
end
{ project: project }
end
end
end
end