diff options
author | James Lopez <james@jameslopez.es> | 2016-11-22 15:05:37 +0100 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2016-11-22 15:05:37 +0100 |
commit | db62eb957157ffe14a474f5f858c753cade067b1 (patch) | |
tree | 3b3c3930fd49c3b338010e5bc23280d684d2426c | |
parent | b1b5060dbad15975184ec20a1914c7c48fc804db (diff) | |
download | gitlab-ce-db62eb957157ffe14a474f5f858c753cade067b1.tar.gz |
fixed bug to do with calculating durations
-rw-r--r-- | app/serializers/analytics_build_entity.rb | 2 | ||||
-rw-r--r-- | app/serializers/entity_date_helper.rb | 2 | ||||
-rw-r--r-- | spec/serializers/analytics_build_entity_spec.rb | 10 |
3 files changed, 11 insertions, 3 deletions
diff --git a/app/serializers/analytics_build_entity.rb b/app/serializers/analytics_build_entity.rb index 5fdf2bbf7c3..abefcd5cc02 100644 --- a/app/serializers/analytics_build_entity.rb +++ b/app/serializers/analytics_build_entity.rb @@ -13,7 +13,7 @@ class AnalyticsBuildEntity < Grape::Entity end 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 expose :branch do diff --git a/app/serializers/entity_date_helper.rb b/app/serializers/entity_date_helper.rb index b333b3344c3..918abba8d99 100644 --- a/app/serializers/entity_date_helper.rb +++ b/app/serializers/entity_date_helper.rb @@ -2,7 +2,7 @@ module EntityDateHelper include ActionView::Helpers::DateHelper def interval_in_words(diff) - "#{distance_of_time_in_words(diff.to_f)} ago" + "#{distance_of_time_in_words(Time.now, diff)} ago" end # Converts seconds into a hash such as: diff --git a/spec/serializers/analytics_build_entity_spec.rb b/spec/serializers/analytics_build_entity_spec.rb index 9ac6f20fd3c..a802c0fa49d 100644 --- a/spec/serializers/analytics_build_entity_spec.rb +++ b/spec/serializers/analytics_build_entity_spec.rb @@ -7,7 +7,7 @@ describe AnalyticsBuildEntity do context 'build with an author' do 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 } @@ -23,5 +23,13 @@ describe AnalyticsBuildEntity do expect(subject).not_to include(/token/) expect(subject).not_to include(/variables/) 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 |