Commit 830f739b authored by James Lopez's avatar James Lopez

use an empty total time when the build has not started yet so the UI knows

parent aa895a64
...@@ -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) build_started?(build) ? distance_of_time_as_hash(build.duration.to_f) : {}
end end
expose :branch do expose :branch do
...@@ -37,4 +37,8 @@ class AnalyticsBuildEntity < Grape::Entity ...@@ -37,4 +37,8 @@ class AnalyticsBuildEntity < Grape::Entity
def url_to(route, build, id = nil) def url_to(route, build, id = nil)
public_send("#{route}_url", build.project.namespace, build.project, id || build) public_send("#{route}_url", build.project.namespace, build.project, id || build)
end end
def build_started?(build)
build.duration && build[:started_at]
end
end end
...@@ -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)
return 'not started' unless diff return 'Not started' unless diff
"#{distance_of_time_in_words(Time.now, diff)} ago" "#{distance_of_time_in_words(Time.now, diff)} ago"
end end
......
...@@ -42,7 +42,13 @@ describe AnalyticsBuildEntity do ...@@ -42,7 +42,13 @@ describe AnalyticsBuildEntity do
expect{ subject[:date] }.not_to raise_error expect{ subject[:date] }.not_to raise_error
end 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 end
context 'no started at date' do context 'no started at date' do
...@@ -51,6 +57,14 @@ describe AnalyticsBuildEntity do ...@@ -51,6 +57,14 @@ describe AnalyticsBuildEntity do
it 'does not blow up' do it 'does not blow up' do
expect{ subject[:date] }.not_to raise_error expect{ subject[:date] }.not_to raise_error
end 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 end
context 'no finished at date' do context 'no finished at date' do
...@@ -59,6 +73,14 @@ describe AnalyticsBuildEntity do ...@@ -59,6 +73,14 @@ describe AnalyticsBuildEntity do
it 'does not blow up' do it 'does not blow up' do
expect{ subject[:date] }.not_to raise_error expect{ subject[:date] }.not_to raise_error
end 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 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