summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/cycle_analytics
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2017-02-06 16:28:17 +0100
committerJames Lopez <james@jameslopez.es>2017-02-06 16:28:17 +0100
commit682e354df649c4aad7b28e6fd16aae3eccbf7e08 (patch)
treec4e44da5768d428825375fb7c54b79d1ff5ac510 /spec/lib/gitlab/cycle_analytics
parent1b7c186723ebf2cd4b97481f3bd7e7285efbc792 (diff)
downloadgitlab-ce-682e354df649c4aad7b28e6fd16aae3eccbf7e08.tar.gz
add spec
Diffstat (limited to 'spec/lib/gitlab/cycle_analytics')
-rw-r--r--spec/lib/gitlab/cycle_analytics/base_event_fetcher_spec.rb44
-rw-r--r--spec/lib/gitlab/cycle_analytics/events_query_spec.rb35
2 files changed, 44 insertions, 35 deletions
diff --git a/spec/lib/gitlab/cycle_analytics/base_event_fetcher_spec.rb b/spec/lib/gitlab/cycle_analytics/base_event_fetcher_spec.rb
new file mode 100644
index 00000000000..4aac63e54e2
--- /dev/null
+++ b/spec/lib/gitlab/cycle_analytics/base_event_fetcher_spec.rb
@@ -0,0 +1,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
diff --git a/spec/lib/gitlab/cycle_analytics/events_query_spec.rb b/spec/lib/gitlab/cycle_analytics/events_query_spec.rb
deleted file mode 100644
index 6aac2ed78d9..00000000000
--- a/spec/lib/gitlab/cycle_analytics/events_query_spec.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-require 'spec_helper'
-
-describe Gitlab::CycleAnalytics::EventsQuery do
- let(:max_events) { 3 }
- let(:project) { create(:project) }
- let(:user) { create(:user, :admin) }
- let(:options) { { from: 30.days.ago } }
-
- let(:issue_event) do
- Gitlab::CycleAnalytics::IssueEvent.new(project: project, options: options)
- end
-
- subject { described_class.new(project: project, options: options).execute(issue_event) }
-
- before do
- allow_any_instance_of(Gitlab::ReferenceExtractor).to receive(:issues).and_return(Issue.all)
- stub_const('Gitlab::CycleAnalytics::EventsQuery::MAX_EVENTS', max_events)
-
- setup_events(count: 5)
- 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