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
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
......@@ -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
......
......@@ -42,7 +42,13 @@
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 @@
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 @@
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
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