debian-mirror-gitlab/spec/models/merge_request/metrics_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

105 lines
3 KiB
Ruby
Raw Permalink Normal View History

2019-07-07 11:18:12 +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 MergeRequest::Metrics do
2018-03-17 18:26:18 +05:30
describe 'associations' do
it { is_expected.to belong_to(:merge_request) }
2021-03-11 19:13:27 +05:30
it { is_expected.to belong_to(:target_project).class_name('Project') }
2018-03-17 18:26:18 +05:30
it { is_expected.to belong_to(:latest_closed_by).class_name('User') }
it { is_expected.to belong_to(:merged_by).class_name('User') }
2016-09-29 09:46:39 +05:30
end
2020-10-24 23:57:45 +05:30
describe 'scopes' do
let_it_be(:metrics_1) { create(:merge_request).metrics.tap { |m| m.update!(merged_at: 10.days.ago) } }
let_it_be(:metrics_2) { create(:merge_request).metrics.tap { |m| m.update!(merged_at: 5.days.ago) } }
describe '.merged_after' do
subject { described_class.merged_after(7.days.ago) }
it 'finds the record' do
is_expected.to eq([metrics_2])
end
it "doesn't include record outside of the filter" do
is_expected.not_to include([metrics_1])
end
end
describe '.merged_before' do
subject { described_class.merged_before(7.days.ago) }
it 'finds the record' do
is_expected.to eq([metrics_1])
end
it "doesn't include record outside of the filter" do
is_expected.not_to include([metrics_2])
end
end
2021-03-11 19:13:27 +05:30
describe '.by_target_project' do
let(:target_project) { metrics_1.target_project }
subject { described_class.by_target_project(target_project) }
it 'finds metrics record with the associated target project' do
is_expected.to eq([metrics_1])
end
end
2020-10-24 23:57:45 +05:30
end
2022-01-26 12:08:38 +05:30
it_behaves_like 'cleanup by a loose foreign key' do
let!(:merge_request) { create(:merge_request) }
let!(:parent) { create(:ci_pipeline, project: merge_request.target_project) }
let!(:model) { merge_request.metrics.tap { |metrics| metrics.update!(pipeline: parent) } }
end
2022-07-16 23:28:13 +05:30
describe 'update' do
let(:merge_request) { create(:merge_request) }
let(:metrics) { merge_request.metrics }
before do
metrics.update!(
pipeline_id: 1,
latest_build_started_at: Time.current,
latest_build_finished_at: Time.current
)
end
context 'when pipeline_id is nullified' do
before do
metrics.update!(pipeline_id: nil)
end
it 'nullifies build related columns via DB trigger' do
metrics.reload
expect(metrics.latest_build_started_at).to be_nil
expect(metrics.latest_build_finished_at).to be_nil
end
end
context 'when updated but pipeline_id is not nullified' do
before do
metrics.update!(latest_closed_at: Time.current)
end
it 'does not nullify build related columns' do
metrics.reload
expect(metrics.latest_build_started_at).not_to be_nil
expect(metrics.latest_build_finished_at).not_to be_nil
end
end
end
2023-07-09 08:55:56 +05:30
it_behaves_like 'database events tracking batch 2' do
let(:merge_request) { create(:merge_request) }
let(:record) { merge_request.metrics }
let(:namespace) { nil }
let(:update_params) { { pipeline_id: 1, updated_at: Date.tomorrow } }
end
2016-09-29 09:46:39 +05:30
end