From 747e5c3b6fb6e744bc1fce04f94930fdbb5f9121 Mon Sep 17 00:00:00 2001 From: James Lopez Date: Tue, 15 Nov 2016 09:59:35 +0100 Subject: [PATCH] use request to pass extra parameters --- app/serializers/analytics_generic_entity.rb | 2 +- lib/gitlab/cycle_analytics/events.rb | 4 ++-- spec/serializers/analytics_generic_entity_spec.rb | 4 ++-- spec/serializers/analytics_generic_serializer_spec.rb | 3 +-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/serializers/analytics_generic_entity.rb b/app/serializers/analytics_generic_entity.rb index 2692e9f21f1..e8cad86030e 100644 --- a/app/serializers/analytics_generic_entity.rb +++ b/app/serializers/analytics_generic_entity.rb @@ -17,7 +17,7 @@ class AnalyticsGenericEntity < Grape::Entity end expose :url do |object| - url_to("namespace_project_#{object[:entity]}".to_sym, id: object[:iid].to_s) + url_to("namespace_project_#{request.entity}".to_sym, id: object[:iid].to_s) end private diff --git a/lib/gitlab/cycle_analytics/events.rb b/lib/gitlab/cycle_analytics/events.rb index 8be102c9fa0..077141110d0 100644 --- a/lib/gitlab/cycle_analytics/events.rb +++ b/lib/gitlab/cycle_analytics/events.rb @@ -49,10 +49,10 @@ module Gitlab private - def parse_event(event) + def parse_event(event, entity: :issue) event['author'] = User.find(event.remove('author_id')) - AnalyticsGenericSerializer.new(project: @project).represent(event).as_json + AnalyticsGenericSerializer.new(project: @project, entity: entity).represent(event).as_json end def parse_build_event(event) diff --git a/spec/serializers/analytics_generic_entity_spec.rb b/spec/serializers/analytics_generic_entity_spec.rb index a09dae4520c..7c731da1dd1 100644 --- a/spec/serializers/analytics_generic_entity_spec.rb +++ b/spec/serializers/analytics_generic_entity_spec.rb @@ -10,14 +10,14 @@ describe AnalyticsGenericEntity do id: "1", created_at: "2016-11-12 15:04:02.948604", author: user, - entity: :merge_request } } let(:project) { create(:empty_project) } + let(:request) { EntityRequest.new(project: project, entity: :merge_request) } let(:entity) do - described_class.new(entity_hash, request: double, project: project) + described_class.new(entity_hash, request: request, project: project) end context 'generic entity' do diff --git a/spec/serializers/analytics_generic_serializer_spec.rb b/spec/serializers/analytics_generic_serializer_spec.rb index 4d523878015..452595fb1f5 100644 --- a/spec/serializers/analytics_generic_serializer_spec.rb +++ b/spec/serializers/analytics_generic_serializer_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe AnalyticsGenericSerializer do let(:serializer) do described_class - .new(project: project) + .new(project: project, entity: :merge_request) .represent(resource) end @@ -18,7 +18,6 @@ describe AnalyticsGenericSerializer do id: "1", created_at: "2016-11-12 15:04:02.948604", author: user, - entity: :merge_request } }