diff options
author | Robert Speicher <robert@gitlab.com> | 2017-09-06 19:42:10 +0300 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2017-09-06 19:42:10 +0300 |
commit | 10fd3542225e161de0c82442304a0881ccecc774 (patch) | |
tree | 1ee40598c2e9f555b809a056e5b2bbc0edc652ef /spec/helpers | |
parent | 04f887420999a14c6188db93f7c10add02f514f4 (diff) | |
parent | 0429ad80921cb38229cdbe650d1ca113c24eb88d (diff) |
Merge branch '35441-fix-division-by-zero' into 'master'
Fix division by zero for blame age map
Closes #35441
See merge request !13803
Diffstat (limited to 'spec/helpers')
-rw-r--r-- | spec/helpers/blame_helper_spec.rb | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/spec/helpers/blame_helper_spec.rb b/spec/helpers/blame_helper_spec.rb index b4368516d83..722d21c566f 100644 --- a/spec/helpers/blame_helper_spec.rb +++ b/spec/helpers/blame_helper_spec.rb @@ -35,25 +35,32 @@ describe BlameHelper do end describe '#age_map_class' do - let(:dates) do - [Time.zone.local(2014, 3, 17, 0, 0, 0)] - end - let(:blame_groups) do - [ - { commit: double(committed_date: dates[0]) } - ] - end + let(:date) { Time.zone.local(2014, 3, 17, 0, 0, 0) } + let(:blame_groups) { [{ commit: double(committed_date: date) }] } let(:duration) do - project = double(created_at: dates[0]) + project = double(created_at: date) helper.age_map_duration(blame_groups, project) end it 'returns blame-commit-age-9 when oldest' do - expect(helper.age_map_class(dates[0], duration)).to eq 'blame-commit-age-9' + expect(helper.age_map_class(date, duration)).to eq 'blame-commit-age-9' end it 'returns blame-commit-age-0 class when newest' do expect(helper.age_map_class(duration[:now], duration)).to eq 'blame-commit-age-0' end + + context 'when called on the same day as project creation' do + let(:same_day_duration) do + project = double(created_at: now) + helper.age_map_duration(today_blame_groups, project) + end + let(:today_blame_groups) { [{ commit: double(committed_date: now) }] } + let(:now) { Time.zone.now } + + it 'returns blame-commit-age-0 class' do + expect(helper.age_map_class(duration[:now], same_day_duration)).to eq 'blame-commit-age-0' + end + end end end |