2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-19 03:26:25 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe MergeRequest::Metrics do
|
2017-12-07 12:41:30 -05:00
|
|
|
describe 'associations' do
|
|
|
|
it { is_expected.to belong_to(:merge_request) }
|
|
|
|
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-19 03:26:25 -04:00
|
|
|
end
|
2020-08-05 08:09:45 -04:00
|
|
|
|
2020-08-06 14:09:41 -04:00
|
|
|
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
|
|
|
|
end
|
2016-09-19 03:26:25 -04:00
|
|
|
end
|