diff --git a/lib/gitlab/cycle_analytics/events.rb b/lib/gitlab/cycle_analytics/events.rb index 04cd599f092..d7248b28527 100644 --- a/lib/gitlab/cycle_analytics/events.rb +++ b/lib/gitlab/cycle_analytics/events.rb @@ -11,9 +11,14 @@ module Gitlab def issue_events @fetcher.fetch_issues.each do |event| - event['issue_diff'] = distance_of_time_in_words(event['issue_diff'].to_f) + event['issue_diff'] = interval_in_words(event['issue_diff']) + event['created_at'] = interval_in_words(event['created_at']) end end + + def interval_in_words(diff) + "#{distance_of_time_in_words( diff.to_f)} ago" + end end end end diff --git a/lib/gitlab/cycle_analytics/events_fetcher.rb b/lib/gitlab/cycle_analytics/events_fetcher.rb index 14405f1356a..0920ab73ae1 100644 --- a/lib/gitlab/cycle_analytics/events_fetcher.rb +++ b/lib/gitlab/cycle_analytics/events_fetcher.rb @@ -16,7 +16,7 @@ module Gitlab project(extract_epoch(diff_fn).as('issue_diff'), *issue_projections). order(issue_table[:created_at].desc) - ActiveRecord::Base.connection.execute(query.to_sql) + ActiveRecord::Base.connection.execute(query.to_sql).to_a end def metric_attributes diff --git a/spec/lib/gitlab/cycle_analytics/events_spec.rb b/spec/lib/gitlab/cycle_analytics/events_spec.rb index 543259f7cc2..be62077f01b 100644 --- a/spec/lib/gitlab/cycle_analytics/events_spec.rb +++ b/spec/lib/gitlab/cycle_analytics/events_spec.rb @@ -15,23 +15,23 @@ describe Gitlab::CycleAnalytics::Events do let!(:context) { create(:issue, project: project, created_at: 2.days.ago) } it 'has an issue diff' do - expect(subject.issue_events['issue_diff']).to eq('2 days ago') + expect(subject.issue_events.first['issue_diff']).to eq('2 days ago') end it 'has a title' do - expect(subject.issue_events['title']).to eq(context.title) + expect(subject.issue_events.first['title']).to eq(context.title) end it 'has an iid' do - expect(subject.issue_events['iid']).to eq(context.iid.to_s) + expect(subject.issue_events.first['iid']).to eq(context.iid.to_s) end it 'has a created_at timestamp' do - expect(subject.issue_events['created_at']).to eq('2 days ago') + expect(subject.issue_events.first['created_at']).to end_with('ago') end it "has the author's name" do - expect(subject.issue_events['name']).to eq(context.author.name) + expect(subject.issue_events.first['name']).to eq(context.author.name) end end