2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::CycleAnalytics::BaseEventFetcher do
|
|
|
|
let(:max_events) { 2 }
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:project) { create(:project, :repository) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:user) { create(:user, :admin) }
|
|
|
|
let(:start_time_attrs) { Issue.arel_table[:created_at] }
|
|
|
|
let(:end_time_attrs) { [Issue::Metrics.arel_table[:first_associated_with_milestone_at]] }
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:options) do
|
2017-08-17 22:00:37 +05:30
|
|
|
{ start_time_attrs: start_time_attrs,
|
|
|
|
end_time_attrs: end_time_attrs,
|
2019-10-12 21:52:04 +05:30
|
|
|
from: 30.days.ago,
|
|
|
|
project: project }
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
subject do
|
2019-10-12 21:52:04 +05:30
|
|
|
described_class.new(stage: :issue,
|
2017-08-17 22:00:37 +05:30
|
|
|
options: options).fetch
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(Gitlab::ReferenceExtractor).to receive(:issues).and_return(Issue.all)
|
|
|
|
allow_any_instance_of(described_class).to receive(:serialize) do |event|
|
|
|
|
event
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
allow_any_instance_of(described_class)
|
|
|
|
.to receive(:allowed_ids).and_return(nil)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
stub_const('Gitlab::CycleAnalytics::BaseEventFetcher::MAX_EVENTS', max_events)
|
|
|
|
|
|
|
|
setup_events(count: 3)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'limits the rows to the max number' do
|
|
|
|
expect(subject.count).to eq(max_events)
|
|
|
|
end
|
|
|
|
|
|
|
|
def setup_events(count:)
|
|
|
|
count.times do
|
|
|
|
issue = create(:issue, project: project, created_at: 2.days.ago)
|
|
|
|
milestone = create(:milestone, project: project)
|
|
|
|
|
|
|
|
issue.update(milestone: milestone)
|
2018-03-27 19:54:05 +05:30
|
|
|
create_merge_request_closing_issue(user, project, issue)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|