Commit f5600997 authored by James Lopez's avatar James Lopez

fix issue events and related spec - now using generic serializer for a hash

parent 747e5c3b
......@@ -5,14 +5,13 @@ class AnalyticsGenericEntity < Grape::Entity
expose :title
expose :iid
expose :started_at, as: :date
expose :author, using: UserEntity
expose :total_time do |object|
distance_of_time_in_words(object[:total_time].to_f)
end
expose(:date) do |object|
expose(:created_at) do |object|
interval_in_words(object[:created_at])
end
......@@ -22,7 +21,7 @@ class AnalyticsGenericEntity < Grape::Entity
private
def url_to(route, id = nil)
def url_to(route, id)
public_send("#{route}_url", request.project.namespace, request.project, id)
end
......
class AnalyticsGenericSerializer < BaseSerializer
entity AnalyticsGenericEntity
def represent(resource, opts = {})
resource.symbolize_keys!
super(resource, opts)
end
end
......@@ -7,7 +7,7 @@ module Gitlab
end
def issue_events
@fetcher.fetch(stage: :issue).each { |event| parse_event(event) }
@fetcher.fetch(stage: :issue).map { |event| parse_event(event) }
end
def plan_events
......@@ -24,7 +24,7 @@ module Gitlab
end
def code_events
@fetcher.fetch(stage: :code).each { |event| parse_event(event, entity: :merge_request) }
@fetcher.fetch(stage: :code).map { |event| parse_event(event, entity: :merge_request) }
end
def test_events
......@@ -34,7 +34,7 @@ module Gitlab
end
def review_events
@fetcher.fetch(stage: :review).each { |event| parse_event(event) }
@fetcher.fetch(stage: :review).map { |event| parse_event(event) }
end
def staging_events
......@@ -50,7 +50,7 @@ module Gitlab
private
def parse_event(event, entity: :issue)
event['author'] = User.find(event.remove('author_id'))
event['author'] = User.find(event.delete('author_id'))
AnalyticsGenericSerializer.new(project: @project, entity: entity).represent(event).as_json
end
......
......@@ -34,15 +34,15 @@ describe Gitlab::CycleAnalytics::Events do
end
it "has the author's URL" do
expect(subject.issue_events.first[:author_profile_url]).not_to be_nil
expect(subject.issue_events.first[:author][:web_url]).not_to be_nil
end
it "has the author's avatar URL" do
expect(subject.issue_events.first[:author_avatar_url]).not_to be_nil
expect(subject.issue_events.first[:author][:avatar_url]).not_to be_nil
end
it "has the author's name" do
expect(subject.issue_events.first[:author_name]).to eq(context.author.name)
expect(subject.issue_events.first[:author][:name]).to eq(context.author.name)
end
end
......
......@@ -27,7 +27,7 @@ describe AnalyticsGenericSerializer do
end
it 'contains important elements of analyticsBuild' do
expect(json).to include(:title, :iid, :date, :total_time, :url, :author)
expect(json).to include(:title, :iid, :created_at, :total_time, :url, :author)
end
end
end
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