diff options
-rw-r--r-- | app/serializers/analytics_stage_entity.rb | 5 | ||||
-rw-r--r-- | changelogs/unreleased/30138-display-cycle-analytics-issue.yml | 5 | ||||
-rw-r--r-- | spec/serializers/analytics_stage_serializer_spec.rb | 30 |
3 files changed, 38 insertions, 2 deletions
diff --git a/app/serializers/analytics_stage_entity.rb b/app/serializers/analytics_stage_entity.rb index ae7c20c3bba..8bc6da5aeeb 100644 --- a/app/serializers/analytics_stage_entity.rb +++ b/app/serializers/analytics_stage_entity.rb @@ -9,7 +9,8 @@ class AnalyticsStageEntity < Grape::Entity expose :description expose :median, as: :value do |stage| - # median returns a BatchLoader instance which we first have to unwrap by using to_i - !stage.median.to_i.zero? ? distance_of_time_in_words(stage.median) : nil + # median returns a BatchLoader instance which we first have to unwrap by using to_f + # we use to_f to make sure results below 1 are presented to the end-user + stage.median.to_f.nonzero? ? distance_of_time_in_words(stage.median) : nil end end diff --git a/changelogs/unreleased/30138-display-cycle-analytics-issue.yml b/changelogs/unreleased/30138-display-cycle-analytics-issue.yml new file mode 100644 index 00000000000..c7faa0480bd --- /dev/null +++ b/changelogs/unreleased/30138-display-cycle-analytics-issue.yml @@ -0,0 +1,5 @@ +--- +title: Show data on Cycle Analytics page when value is less than a second +merge_request: 28507 +author: +type: fixed diff --git a/spec/serializers/analytics_stage_serializer_spec.rb b/spec/serializers/analytics_stage_serializer_spec.rb index dbfb3eace83..5b05c2f2ef3 100644 --- a/spec/serializers/analytics_stage_serializer_spec.rb +++ b/spec/serializers/analytics_stage_serializer_spec.rb @@ -21,4 +21,34 @@ describe AnalyticsStageSerializer do it 'contains important elements of AnalyticsStage' do expect(subject).to include(:title, :description, :value) end + + context 'when median is equal 0' do + before do + allow_any_instance_of(Gitlab::CycleAnalytics::BaseStage).to receive(:median).and_return(0) + end + + it 'sets the value to nil' do + expect(subject.fetch(:value)).to be_nil + end + end + + context 'when median is below 1' do + before do + allow_any_instance_of(Gitlab::CycleAnalytics::BaseStage).to receive(:median).and_return(0.12) + end + + it 'sets the value to equal to median' do + expect(subject.fetch(:value)).to eq('less than a minute') + end + end + + context 'when median is above 1' do + before do + allow_any_instance_of(Gitlab::CycleAnalytics::BaseStage).to receive(:median).and_return(60.12) + end + + it 'sets the value to equal to median' do + expect(subject.fetch(:value)).to eq('1 minute') + end + end end |