use request to pass extra parameters
This commit is contained in:
parent
6a2737e6a8
commit
747e5c3b6f
4 changed files with 6 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue