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