2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::CycleAnalytics::StageSummary do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:project) { create(:project, :repository) }
|
2019-12-21 20:55:43 +05:30
|
|
|
let(:options) { { from: 1.day.ago, current_user: user } }
|
2016-09-29 09:46:39 +05:30
|
|
|
let(:user) { create(:user, :admin) }
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
before do
|
|
|
|
project.add_maintainer(user)
|
|
|
|
end
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
let(:stage_summary) { described_class.new(project, **options).data }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
describe "#new_issues" do
|
2020-06-23 00:09:42 +05:30
|
|
|
subject { stage_summary.first }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
context 'when from date is given' do
|
|
|
|
before do
|
|
|
|
Timecop.freeze(5.days.ago) { create(:issue, project: project) }
|
|
|
|
Timecop.freeze(5.days.from_now) { create(:issue, project: project) }
|
|
|
|
end
|
|
|
|
|
|
|
|
it "finds the number of issues created after the 'from date'" do
|
|
|
|
expect(subject[:value]).to eq('1')
|
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
it 'returns the localized title' do
|
|
|
|
Gitlab::I18n.with_locale(:ru) do
|
|
|
|
expect(subject[:title]).to eq(n_('New Issue', 'New Issues', 1))
|
|
|
|
end
|
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't find issues from other projects" do
|
2017-09-10 17:25:29 +05:30
|
|
|
Timecop.freeze(5.days.from_now) { create(:issue, project: create(:project)) }
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(subject[:value]).to eq('-')
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when `to` parameter is given' do
|
|
|
|
before do
|
|
|
|
Timecop.freeze(5.days.ago) { create(:issue, project: project) }
|
|
|
|
Timecop.freeze(5.days.from_now) { create(:issue, project: project) }
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't find any record" do
|
|
|
|
options[:to] = Time.now
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(subject[:value]).to eq('-')
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "finds records created between `from` and `to` range" do
|
|
|
|
options[:from] = 10.days.ago
|
|
|
|
options[:to] = 10.days.from_now
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(subject[:value]).to eq('2')
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#commits" do
|
2020-06-23 00:09:42 +05:30
|
|
|
subject { stage_summary.second }
|
|
|
|
|
|
|
|
context 'when from date is given' do
|
|
|
|
before do
|
|
|
|
Timecop.freeze(5.days.ago) { create_commit("Test message", project, user, 'master') }
|
|
|
|
Timecop.freeze(5.days.from_now) { create_commit("Test message", project, user, 'master') }
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
it "finds the number of commits created after the 'from date'" do
|
|
|
|
expect(subject[:value]).to eq('1')
|
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
it 'returns the localized title' do
|
|
|
|
Gitlab::I18n.with_locale(:ru) do
|
|
|
|
expect(subject[:title]).to eq(n_('Commit', 'Commits', 1))
|
|
|
|
end
|
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't find commits from other projects" do
|
2017-08-17 22:00:37 +05:30
|
|
|
Timecop.freeze(5.days.from_now) { create_commit("Test message", create(:project, :repository), user, 'master') }
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(subject[:value]).to eq('-')
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
2016-10-01 15:18:49 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
it "finds a large (> 100) number of commits if present" do
|
2016-10-01 15:18:49 +05:30
|
|
|
Timecop.freeze(5.days.from_now) { create_commit("Test message", project, user, 'master', count: 100) }
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(subject[:value]).to eq('100')
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when `to` parameter is given' do
|
|
|
|
before do
|
|
|
|
Timecop.freeze(5.days.ago) { create_commit("Test message", project, user, 'master') }
|
|
|
|
Timecop.freeze(5.days.from_now) { create_commit("Test message", project, user, 'master') }
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't find any record" do
|
|
|
|
options[:to] = Time.now
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(subject[:value]).to eq('-')
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "finds records created between `from` and `to` range" do
|
|
|
|
options[:from] = 10.days.ago
|
|
|
|
options[:to] = 10.days.from_now
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(subject[:value]).to eq('2')
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
2016-10-01 15:18:49 +05:30
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
context 'when a guest user is signed in' do
|
|
|
|
let(:guest_user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_guest(guest_user)
|
2019-12-21 20:55:43 +05:30
|
|
|
options.merge!({ current_user: guest_user })
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not include commit stats' do
|
2021-02-22 17:27:13 +05:30
|
|
|
data = described_class.new(project, **options).data
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(includes_commits?(data)).to be_falsy
|
|
|
|
end
|
|
|
|
|
|
|
|
def includes_commits?(data)
|
|
|
|
data.any? { |h| h["title"] == 'Commits' }
|
|
|
|
end
|
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe "#deploys" do
|
2020-06-23 00:09:42 +05:30
|
|
|
subject { stage_summary.third }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
context 'when from date is given' do
|
|
|
|
before do
|
|
|
|
Timecop.freeze(5.days.ago) { create(:deployment, :success, project: project) }
|
|
|
|
Timecop.freeze(5.days.from_now) { create(:deployment, :success, project: project) }
|
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
it "finds the number of deploys made created after the 'from date'" do
|
|
|
|
expect(subject[:value]).to eq('1')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the localized title' do
|
|
|
|
Gitlab::I18n.with_locale(:ru) do
|
|
|
|
expect(subject[:title]).to eq(n_('Deploy', 'Deploys', 1))
|
|
|
|
end
|
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't find commits from other projects" do
|
2017-08-17 22:00:37 +05:30
|
|
|
Timecop.freeze(5.days.from_now) do
|
2018-12-13 13:39:08 +05:30
|
|
|
create(:deployment, :success, project: create(:project, :repository))
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(subject[:value]).to eq('-')
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when `to` parameter is given' do
|
|
|
|
before do
|
|
|
|
Timecop.freeze(5.days.ago) { create(:deployment, :success, project: project) }
|
|
|
|
Timecop.freeze(5.days.from_now) { create(:deployment, :success, project: project) }
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't find any record" do
|
|
|
|
options[:to] = Time.now
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(subject[:value]).to eq('-')
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "finds records created between `from` and `to` range" do
|
|
|
|
options[:from] = 10.days.ago
|
|
|
|
options[:to] = 10.days.from_now
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(subject[:value]).to eq('2')
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#deployment_frequency' do
|
|
|
|
subject { stage_summary.fourth[:value] }
|
|
|
|
|
|
|
|
it 'includes the unit: `per day`' do
|
|
|
|
expect(stage_summary.fourth[:unit]).to eq _('per day')
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
Timecop.freeze(5.days.ago) { create(:deployment, :success, project: project) }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 0.0 when there were deploys but the frequency was too low' do
|
|
|
|
options[:from] = 30.days.ago
|
|
|
|
|
|
|
|
# 1 deployment over 30 days
|
|
|
|
# frequency of 0.03, rounded off to 0.0
|
|
|
|
expect(subject).to eq('0')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns `-` when there were no deploys' do
|
|
|
|
options[:from] = 4.days.ago
|
|
|
|
|
|
|
|
# 0 deployment in the last 4 days
|
|
|
|
expect(subject).to eq('-')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when `to` is nil' do
|
|
|
|
it 'includes range until now' do
|
|
|
|
options[:from] = 6.days.ago
|
|
|
|
options[:to] = nil
|
|
|
|
|
|
|
|
# 1 deployment over 7 days
|
|
|
|
expect(subject).to eq('0.1')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when `to` is given' do
|
|
|
|
before do
|
|
|
|
Timecop.freeze(5.days.from_now) { create(:deployment, :success, project: project) }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'finds records created between `from` and `to` range' do
|
|
|
|
options[:from] = 10.days.ago
|
|
|
|
options[:to] = 10.days.from_now
|
|
|
|
|
|
|
|
# 2 deployments over 20 days
|
|
|
|
expect(subject).to eq('0.1')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when `from` and `to` are within a day' do
|
|
|
|
it 'returns the number of deployments made on that day' do
|
2020-11-24 15:15:51 +05:30
|
|
|
freeze_time do
|
2020-04-22 19:07:51 +05:30
|
|
|
create(:deployment, :success, project: project)
|
|
|
|
options[:from] = options[:to] = Time.now
|
|
|
|
|
|
|
|
expect(subject).to eq('1')
|
|
|
|
end
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|