summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2016-11-25 11:22:44 +0100
committerJames Lopez <james@jameslopez.es>2016-11-25 11:47:33 +0100
commit830f739b99b36f8862dadc524e4aa72ec5a3366e (patch)
tree744f10d8900493e2443b36d432cd6ed0f5e76f24
parentaa895a64d928f8292ff9df526831ae74d250f748 (diff)
downloadgitlab-ce-830f739b99b36f8862dadc524e4aa72ec5a3366e.tar.gz
use an empty total time when the build has not started yet so the UI knows
-rw-r--r--app/serializers/analytics_build_entity.rb6
-rw-r--r--app/serializers/entity_date_helper.rb2
-rw-r--r--spec/serializers/analytics_build_entity_spec.rb24
3 files changed, 29 insertions, 3 deletions
diff --git a/app/serializers/analytics_build_entity.rb b/app/serializers/analytics_build_entity.rb
index abefcd5cc02..206a7eadbcf 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)
+ build_started?(build) ? distance_of_time_as_hash(build.duration.to_f) : {}
end
expose :branch do
@@ -37,4 +37,8 @@ class AnalyticsBuildEntity < Grape::Entity
def url_to(route, build, id = nil)
public_send("#{route}_url", build.project.namespace, build.project, id || build)
end
+
+ def build_started?(build)
+ build.duration && build[:started_at]
+ end
end
diff --git a/app/serializers/entity_date_helper.rb b/app/serializers/entity_date_helper.rb
index 3cc98fb18a1..9607ad55a8b 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)
- return 'not started' unless diff
+ return 'Not started' unless diff
"#{distance_of_time_in_words(Time.now, diff)} ago"
end
diff --git a/spec/serializers/analytics_build_entity_spec.rb b/spec/serializers/analytics_build_entity_spec.rb
index ba562353661..1a9ad1968bd 100644
--- a/spec/serializers/analytics_build_entity_spec.rb
+++ b/spec/serializers/analytics_build_entity_spec.rb
@@ -42,7 +42,13 @@ describe AnalyticsBuildEntity do
expect{ subject[:date] }.not_to raise_error
end
- it ''
+ it 'shows the right message' do
+ expect(subject[:date]).to eq('Not started')
+ end
+
+ it 'shows the right total time' do
+ expect(subject[:total_time]).to eq({})
+ end
end
context 'no started at date' do
@@ -51,6 +57,14 @@ describe AnalyticsBuildEntity do
it 'does not blow up' do
expect{ subject[:date] }.not_to raise_error
end
+
+ it 'shows the right message' do
+ expect(subject[:date]).to eq('Not started')
+ end
+
+ it 'shows the right total time' do
+ expect(subject[:total_time]).to eq({})
+ end
end
context 'no finished at date' do
@@ -59,6 +73,14 @@ describe AnalyticsBuildEntity do
it 'does not blow up' do
expect{ subject[:date] }.not_to raise_error
end
+
+ it 'shows the right message' do
+ expect(subject[:date]).to eq('about 2 hours ago')
+ end
+
+ it 'shows the right total time' do
+ expect(subject[:total_time]).to eq({hours: 2})
+ end
end
end
end