Commit d99cec7f authored by James Lopez's avatar James Lopez

review events - spec and logic

parent ebd5ced7
......@@ -13,10 +13,7 @@ module Gitlab
def issue_events
# TODO figure out what the frontend needs for displaying the avatar
@fetcher.fetch_issue_events.each do |event|
event['total_time'] = distance_of_time_in_words(event['total_time'].to_f)
event['created_at'] = interval_in_words(event['created_at'])
end
@fetcher.fetch_issue_events { |event| parse_event(event) }
end
def plan_events
......@@ -28,10 +25,7 @@ module Gitlab
end
def code_events
@fetcher.fetch_code_events.each do |event|
event['total_time'] = distance_of_time_in_words(event['total_time'].to_f)
event['created_at'] = interval_in_words(event['created_at'])
end
@fetcher.fetch_code_events { |event| parse_event(event) }
end
def test_events
......@@ -41,6 +35,15 @@ module Gitlab
end
end
def review_events
@fetcher.fetch_review_events.each { |event| parse_event(event) }
end
def parse_event(event)
event['total_time'] = distance_of_time_in_words(event['total_time'].to_f)
event['created_at'] = interval_in_words(event['created_at'])
end
private
def first_time_reference_commit(commits, event)
......
......@@ -57,6 +57,19 @@ module Gitlab
execute(query)
end
def fetch_review_events
base_query = base_query_for(:code)
diff_fn = subtract_datetimes_diff(base_query,
mr_table[:created_at],
mr_metrics_table[:merged_at])
query = base_query.join(user_table).on(mr_table[:author_id].eq(user_table[:id])).
project(extract_epoch(diff_fn).as('total_time'), *code_projections).
order(mr_table[:created_at].desc)
execute(query)
end
private
def issue_attributes
......
......@@ -97,6 +97,31 @@ describe Gitlab::CycleAnalytics::Events do
end
end
describe '#review_events' do
let!(:context) { create(:issue, project: project, created_at: 2.days.ago) }
it 'has the total time' do
expect(subject.review_events.first['total_time']).to eq('less than a minute')
end
it 'has a title' do
expect(subject.review_events.first['title']).to eq('Awesome merge_request')
end
it 'has an iid' do
expect(subject.review_events.first['iid']).to eq(context.iid.to_s)
end
it 'has a created_at timestamp' do
expect(subject.review_events.first['created_at']).to end_with('ago')
end
it "has the author's name" do
expect(subject.review_events.first['name']).to eq(MergeRequest.first.author.name)
end
end
def setup(context)
milestone = create(:milestone, project: project)
context.update(milestone: milestone)
......
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