Commit c545968e authored by James Lopez's avatar James Lopez

fix timestamp diff and spec

parent 847d2796
module Gitlab
module CycleAnalytics
class Events
include ActionView::Helpers::DateHelper
def initialize(project:, from:)
@project = project
@from = from
......@@ -8,7 +10,9 @@ module Gitlab
end
def issue_events
@fetcher.fetch_issues
@fetcher.fetch_issues.each do |event|
event['issue_diff'] = distance_of_time_in_words(event['issue_diff'].to_f)
end
end
end
end
......
......@@ -13,10 +13,10 @@ module Gitlab
diff_fn = subtract_datetimes_diff(base_query, issue_table[:created_at], metric_attributes)
query = base_query.join(user_table).on(issue_table[:author_id].eq(user_table[:id])).
project(diff_fn.as('issue_diff'), *issue_projections).
project(extract_epoch(diff_fn).as('issue_diff'), *issue_projections).
order(issue_table[:created_at].desc)
ActiveRecord::Base.connection.execute(query.to_sql).first
ActiveRecord::Base.connection.execute(query.to_sql)
end
def metric_attributes
......@@ -31,6 +31,10 @@ module Gitlab
def user_table
User.arel_table
end
def extract_epoch(arel_attribute)
Arel.sql(%Q{EXTRACT(EPOCH FROM (#{arel_attribute.to_sql}))})
end
end
end
end
......@@ -12,10 +12,10 @@ describe Gitlab::CycleAnalytics::Events do
end
describe '#issue' do
let!(:context) { create(:issue, project: project) }
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("-00:00:00.339259")
expect(subject.issue_events['issue_diff']).to eq('2 days ago')
end
it 'has a title' do
......@@ -23,11 +23,11 @@ describe Gitlab::CycleAnalytics::Events do
end
it 'has an iid' do
expect(subject.issue_events['iid']).to eq(context.iid)
expect(subject.issue_events['iid']).to eq(context.iid.to_s)
end
it 'has a created_at timestamp' do
expect(subject.issue_events['created_at']).to eq(context.created_at)
expect(subject.issue_events['created_at']).to eq('2 days ago')
end
it "has the author's name" do
......
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