2019-09-30 08:06:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-10-30 17:41:13 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 05:08:32 -04:00
|
|
|
RSpec.describe BlameHelper do
|
2016-10-30 17:41:13 -04:00
|
|
|
describe '#get_age_map_start_date' do
|
|
|
|
let(:dates) do
|
|
|
|
[Time.zone.local(2014, 3, 17, 0, 0, 0),
|
|
|
|
Time.zone.local(2011, 11, 2, 0, 0, 0),
|
|
|
|
Time.zone.local(2015, 7, 9, 0, 0, 0),
|
|
|
|
Time.zone.local(2013, 2, 24, 0, 0, 0),
|
|
|
|
Time.zone.local(2010, 9, 22, 0, 0, 0)]
|
|
|
|
end
|
2020-08-10 23:11:00 -04:00
|
|
|
|
2016-10-30 17:41:13 -04:00
|
|
|
let(:blame_groups) do
|
|
|
|
[
|
|
|
|
{ commit: double(committed_date: dates[0]) },
|
|
|
|
{ commit: double(committed_date: dates[1]) },
|
|
|
|
{ commit: double(committed_date: dates[2]) }
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the earliest date from a blame group' do
|
|
|
|
project = double(created_at: dates[3])
|
|
|
|
|
|
|
|
duration = helper.age_map_duration(blame_groups, project)
|
|
|
|
|
|
|
|
expect(duration[:started_days_ago]).to eq((duration[:now] - dates[1]).to_i / 1.day)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the earliest date from a project' do
|
|
|
|
project = double(created_at: dates[4])
|
|
|
|
|
|
|
|
duration = helper.age_map_duration(blame_groups, project)
|
|
|
|
|
|
|
|
expect(duration[:started_days_ago]).to eq((duration[:now] - dates[4]).to_i / 1.day)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#age_map_class' do
|
2017-09-05 17:57:37 -04:00
|
|
|
let(:date) { Time.zone.local(2014, 3, 17, 0, 0, 0) }
|
|
|
|
let(:blame_groups) { [{ commit: double(committed_date: date) }] }
|
2016-10-30 17:41:13 -04:00
|
|
|
let(:duration) do
|
2017-09-05 17:57:37 -04:00
|
|
|
project = double(created_at: date)
|
2016-10-30 17:41:13 -04:00
|
|
|
helper.age_map_duration(blame_groups, project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns blame-commit-age-9 when oldest' do
|
2017-09-05 17:57:37 -04:00
|
|
|
expect(helper.age_map_class(date, duration)).to eq 'blame-commit-age-9'
|
2016-10-30 17:41:13 -04:00
|
|
|
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
|
2017-08-24 10:50:47 -04:00
|
|
|
|
2017-09-05 17:57:37 -04:00
|
|
|
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
|
2020-08-10 23:11:00 -04:00
|
|
|
|
2017-09-05 17:57:37 -04:00
|
|
|
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
|
2017-08-24 10:50:47 -04:00
|
|
|
end
|
2016-10-30 17:41:13 -04:00
|
|
|
end
|
|
|
|
end
|