fix timestamp diff and spec
This commit is contained in:
parent
847d2796cf
commit
c545968ece
3 changed files with 15 additions and 7 deletions
|
@ -1,6 +1,8 @@
|
||||||
module Gitlab
|
module Gitlab
|
||||||
module CycleAnalytics
|
module CycleAnalytics
|
||||||
class Events
|
class Events
|
||||||
|
include ActionView::Helpers::DateHelper
|
||||||
|
|
||||||
def initialize(project:, from:)
|
def initialize(project:, from:)
|
||||||
@project = project
|
@project = project
|
||||||
@from = from
|
@from = from
|
||||||
|
@ -8,7 +10,9 @@ module Gitlab
|
||||||
end
|
end
|
||||||
|
|
||||||
def issue_events
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,10 +13,10 @@ module Gitlab
|
||||||
diff_fn = subtract_datetimes_diff(base_query, issue_table[:created_at], metric_attributes)
|
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])).
|
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)
|
order(issue_table[:created_at].desc)
|
||||||
|
|
||||||
ActiveRecord::Base.connection.execute(query.to_sql).first
|
ActiveRecord::Base.connection.execute(query.to_sql)
|
||||||
end
|
end
|
||||||
|
|
||||||
def metric_attributes
|
def metric_attributes
|
||||||
|
@ -31,6 +31,10 @@ module Gitlab
|
||||||
def user_table
|
def user_table
|
||||||
User.arel_table
|
User.arel_table
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def extract_epoch(arel_attribute)
|
||||||
|
Arel.sql(%Q{EXTRACT(EPOCH FROM (#{arel_attribute.to_sql}))})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,10 +12,10 @@ describe Gitlab::CycleAnalytics::Events do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#issue' do
|
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
|
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
|
end
|
||||||
|
|
||||||
it 'has a title' do
|
it 'has a title' do
|
||||||
|
@ -23,11 +23,11 @@ describe Gitlab::CycleAnalytics::Events do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'has an iid' do
|
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
|
end
|
||||||
|
|
||||||
it 'has a created_at timestamp' do
|
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
|
end
|
||||||
|
|
||||||
it "has the author's name" do
|
it "has the author's name" do
|
||||||
|
|
Loading…
Reference in a new issue