Welcome to mirror list, hosted at ThFree Co, Russian Federation.

base_event_fetcher_spec.rb « cycle_analytics « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4aac63e54e2f235aa162dfbdcc94c2c3bf9feb8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require 'spec_helper'

describe Gitlab::CycleAnalytics::BaseEventFetcher do
  let(:max_events) { 2 }
  let(:project) { create(:project) }
  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]] }
  let(:options) { { start_time_attrs: start_time_attrs,
                    end_time_attrs: end_time_attrs,
                    from: 30.days.ago } }


  subject do
    described_class.new(project: project,
                        stage: :issue,
                        options: options).fetch
  end

  before do
    allow_any_instance_of(Gitlab::ReferenceExtractor).to receive(:issues).and_return(Issue.all)
    allow_any_instance_of(Gitlab::CycleAnalytics::BaseEventFetcher).to receive(:serialize) do |event|
      event
    end

    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)
      create_merge_request_closing_issue(issue)
    end
  end
end