Commit db62eb95 authored by James Lopez's avatar James Lopez

fixed bug to do with calculating durations

parent b1b5060d
...@@ -13,7 +13,7 @@ class AnalyticsBuildEntity < Grape::Entity ...@@ -13,7 +13,7 @@ class AnalyticsBuildEntity < Grape::Entity
end end
expose :duration, as: :total_time do |build| expose :duration, as: :total_time do |build|
distance_of_time_as_hash(build[:duration].to_f) distance_of_time_as_hash(build.duration.to_f)
end end
expose :branch do expose :branch do
......
...@@ -2,7 +2,7 @@ module EntityDateHelper ...@@ -2,7 +2,7 @@ module EntityDateHelper
include ActionView::Helpers::DateHelper include ActionView::Helpers::DateHelper
def interval_in_words(diff) def interval_in_words(diff)
"#{distance_of_time_in_words(diff.to_f)} ago" "#{distance_of_time_in_words(Time.now, diff)} ago"
end end
# Converts seconds into a hash such as: # Converts seconds into a hash such as:
......
...@@ -7,7 +7,7 @@ describe AnalyticsBuildEntity do ...@@ -7,7 +7,7 @@ describe AnalyticsBuildEntity do
context 'build with an author' do context 'build with an author' do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:build) { create(:ci_build, author: user) } let(:build) { create(:ci_build, author: user, started_at: 2.hours.ago, finished_at: 1.hour.ago) }
subject { entity.as_json } subject { entity.as_json }
...@@ -23,5 +23,13 @@ describe AnalyticsBuildEntity do ...@@ -23,5 +23,13 @@ describe AnalyticsBuildEntity do
expect(subject).not_to include(/token/) expect(subject).not_to include(/token/)
expect(subject).not_to include(/variables/) expect(subject).not_to include(/variables/)
end end
it 'contains the right started at' do
expect(subject[:date]).to eq('about 2 hours ago')
end
it 'contains the duration' do
expect(subject[:total_time]).to eq({ :hours => 1 })
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