debian-mirror-gitlab/spec/serializers/merge_request_metrics_helper_spec.rb

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

70 lines
1.9 KiB
Ruby
Raw Normal View History

2021-11-18 22:05:49 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe MergeRequestMetricsHelper do
let_it_be(:user) { create(:user) }
let(:merge_request) { create(:merge_request) }
let(:helper) { Class.new.include(described_class).new }
describe '#build_metrics' do
subject do
helper.build_metrics(merge_request)
end
shared_examples 'does not rebuild the metrics' do
it 'does not call the merge request metrics class' do
expect(MergeRequest::Metrics).not_to receive(:new)
subject
end
it 'returns the metrics for the given merge request' do
expect(subject).to be_kind_of(MergeRequest::Metrics)
expect(subject[:merge_request_id]).to eq(merge_request.id)
end
end
context 'when closed and metrics exists' do
before do
merge_request.close!
merge_request.metrics.update!(latest_closed_by: user)
end
include_examples 'does not rebuild the metrics'
end
context 'when merged and metrics exists' do
before do
merge_request.mark_as_merged!
merge_request.metrics.update!(merged_by: user)
end
include_examples 'does not rebuild the metrics'
end
context 'when merged and metrics do not exists' do
before do
merge_request.mark_as_merged!
merge_request.metrics.destroy!
merge_request.reload
end
it 'rebuilds the merge request metrics' do
closed_event = merge_request.closed_event
merge_event = merge_request.merge_event
expect(MergeRequest::Metrics).to receive(:new)
.with(latest_closed_at: closed_event&.updated_at,
2022-10-11 01:57:18 +05:30
latest_closed_by: closed_event&.author,
merged_at: merge_event&.updated_at,
merged_by: merge_event&.author)
2021-11-18 22:05:49 +05:30
.and_call_original
subject
end
end
end
end