summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2016-12-05 09:47:10 +0100
committerJames Lopez <james@jameslopez.es>2017-01-17 11:32:55 +0100
commit3f681f4cefb5eda594acaab2eaf1be18ebd9066c (patch)
tree70cb52af2bf1bf07ea94d847b0ed5a7620c16bc9
parentb214be493d9f179d4a929ee32d94a336da7b38f1 (diff)
downloadgitlab-ce-3f681f4cefb5eda594acaab2eaf1be18ebd9066c.tar.gz
fix specs, refactor missing bits from events stuff
-rw-r--r--lib/gitlab/cycle_analytics/base_event_fetcher.rb8
-rw-r--r--lib/gitlab/cycle_analytics/base_stage.rb4
-rw-r--r--lib/gitlab/cycle_analytics/event.rb2
-rw-r--r--lib/gitlab/cycle_analytics/metrics_fetcher.rb9
-rw-r--r--spec/lib/gitlab/cycle_analytics/code_event_fetcher_spec.rb4
-rw-r--r--spec/lib/gitlab/cycle_analytics/issue_event_fetcher_spec.rb6
-rw-r--r--spec/lib/gitlab/cycle_analytics/plan_event_fetcher_spec.rb4
-rw-r--r--spec/lib/gitlab/cycle_analytics/production_event_fetcher_spec.rb6
-rw-r--r--spec/lib/gitlab/cycle_analytics/review_event_fetcher_spec.rb6
-rw-r--r--spec/lib/gitlab/cycle_analytics/shared_event_spec.rb8
-rw-r--r--spec/lib/gitlab/cycle_analytics/shared_stage_spec.rb8
-rw-r--r--spec/lib/gitlab/cycle_analytics/staging_event_fetcher_spec.rb4
-rw-r--r--spec/lib/gitlab/cycle_analytics/test_event_fetcher_spec.rb4
13 files changed, 29 insertions, 44 deletions
diff --git a/lib/gitlab/cycle_analytics/base_event_fetcher.rb b/lib/gitlab/cycle_analytics/base_event_fetcher.rb
index 0d851f81b1d..d4b2d665e59 100644
--- a/lib/gitlab/cycle_analytics/base_event_fetcher.rb
+++ b/lib/gitlab/cycle_analytics/base_event_fetcher.rb
@@ -3,7 +3,7 @@ module Gitlab
class BaseEventFetcher
include MetricsTables
- attr_reader :projections, :query, :stage
+ attr_reader :projections, :query, :stage, :order
def initialize(fetcher:, options:, stage:)
@fetcher = fetcher
@@ -22,10 +22,6 @@ module Gitlab
def custom_query(_base_query); end
- def order
- @order || @start_time_attrs
- end
-
private
def update_author!
@@ -35,7 +31,7 @@ module Gitlab
end
def event_result
- @event_result ||= @fetcher.events(self).to_a
+ @event_result ||= @fetcher.events.to_a
end
def serialize(_event)
diff --git a/lib/gitlab/cycle_analytics/base_stage.rb b/lib/gitlab/cycle_analytics/base_stage.rb
index f3b8bb6e1d3..f81a41bccb6 100644
--- a/lib/gitlab/cycle_analytics/base_stage.rb
+++ b/lib/gitlab/cycle_analytics/base_stage.rb
@@ -1,6 +1,8 @@
module Gitlab
module CycleAnalytics
class BaseStage
+ include MetricsTables
+
attr_accessor :start_time_attrs, :end_time_attrs
def initialize(project:, options:)
@@ -13,7 +15,7 @@ module Gitlab
end
def event
- @event ||= Gitlab::CycleAnalytics::Event[stage].new(fetcher: @fetcher, options: @options)
+ @event ||= Gitlab::CycleAnalytics::Event[stage].new(fetcher: @fetcher, options: @options, stage: stage)
end
def events
diff --git a/lib/gitlab/cycle_analytics/event.rb b/lib/gitlab/cycle_analytics/event.rb
index bb3a5722a0f..1ba7bc08ee5 100644
--- a/lib/gitlab/cycle_analytics/event.rb
+++ b/lib/gitlab/cycle_analytics/event.rb
@@ -2,7 +2,7 @@ module Gitlab
module CycleAnalytics
module Event
def self.[](stage_name)
- CycleAnalytics.const_get("#{stage_name.to_s.camelize}Event")
+ CycleAnalytics.const_get("#{stage_name.to_s.camelize}EventFetcher")
end
end
end
diff --git a/lib/gitlab/cycle_analytics/metrics_fetcher.rb b/lib/gitlab/cycle_analytics/metrics_fetcher.rb
index 865abd0fa6c..dd291840ecd 100644
--- a/lib/gitlab/cycle_analytics/metrics_fetcher.rb
+++ b/lib/gitlab/cycle_analytics/metrics_fetcher.rb
@@ -38,13 +38,16 @@ module Gitlab
def events_query
base_query = base_query_for(@stage.stage)
- event = @stage.event
diff_fn = subtract_datetimes_diff(base_query, @stage.start_time_attrs, @stage.end_time_attrs)
- event_instance.custom_query(base_query)
+ @stage.event.custom_query(base_query)
- base_query.project(extract_diff_epoch(diff_fn).as('total_time'), *event.projections).order(event.order.desc)
+ base_query.project(extract_diff_epoch(diff_fn).as('total_time'), *@stage.event.projections).order(order.desc)
+ end
+
+ def order
+ @stage.event.order || @stage.start_time_attrs.is_a?(Array) ? @stage.start_time_attrs.first : @stage.start_time_attrs
end
# Join table with a row for every <issue,merge_request> pair (where the merge request
diff --git a/spec/lib/gitlab/cycle_analytics/code_event_fetcher_spec.rb b/spec/lib/gitlab/cycle_analytics/code_event_fetcher_spec.rb
index abfd60d7f6a..0267e8c2f69 100644
--- a/spec/lib/gitlab/cycle_analytics/code_event_fetcher_spec.rb
+++ b/spec/lib/gitlab/cycle_analytics/code_event_fetcher_spec.rb
@@ -5,8 +5,8 @@ describe Gitlab::CycleAnalytics::CodeEventFetcher do
let(:stage_name) { :code }
it_behaves_like 'default query config' do
- it 'does not have the default order' do
- expect(event.order).not_to eq(event.start_time_attrs)
+ it 'has a default order' do
+ expect(event.order).not_to be_nil
end
end
end
diff --git a/spec/lib/gitlab/cycle_analytics/issue_event_fetcher_spec.rb b/spec/lib/gitlab/cycle_analytics/issue_event_fetcher_spec.rb
index f4d995d072f..fd9fa2fee49 100644
--- a/spec/lib/gitlab/cycle_analytics/issue_event_fetcher_spec.rb
+++ b/spec/lib/gitlab/cycle_analytics/issue_event_fetcher_spec.rb
@@ -4,9 +4,5 @@ require 'lib/gitlab/cycle_analytics/shared_event_spec'
describe Gitlab::CycleAnalytics::IssueEventFetcher do
let(:stage_name) { :issue }
- it_behaves_like 'default query config' do
- it 'has the default order' do
- expect(event.order).to eq(event.start_time_attrs)
- end
- end
+ it_behaves_like 'default query config'
end
diff --git a/spec/lib/gitlab/cycle_analytics/plan_event_fetcher_spec.rb b/spec/lib/gitlab/cycle_analytics/plan_event_fetcher_spec.rb
index 679779de51e..1c3c1728fc6 100644
--- a/spec/lib/gitlab/cycle_analytics/plan_event_fetcher_spec.rb
+++ b/spec/lib/gitlab/cycle_analytics/plan_event_fetcher_spec.rb
@@ -5,10 +5,6 @@ describe Gitlab::CycleAnalytics::PlanEventFetcher do
let(:stage_name) { :plan }
it_behaves_like 'default query config' do
- it 'has the default order' do
- expect(event.order).to eq(event.start_time_attrs)
- end
-
context 'no commits' do
it 'does not blow up if there are no commits' do
allow_any_instance_of(Gitlab::CycleAnalytics::MetricsFetcher).to receive(:events).and_return([{}])
diff --git a/spec/lib/gitlab/cycle_analytics/production_event_fetcher_spec.rb b/spec/lib/gitlab/cycle_analytics/production_event_fetcher_spec.rb
index a9126b8fa1c..74001181305 100644
--- a/spec/lib/gitlab/cycle_analytics/production_event_fetcher_spec.rb
+++ b/spec/lib/gitlab/cycle_analytics/production_event_fetcher_spec.rb
@@ -4,9 +4,5 @@ require 'lib/gitlab/cycle_analytics/shared_event_spec'
describe Gitlab::CycleAnalytics::ProductionEventFetcher do
let(:stage_name) { :production }
- it_behaves_like 'default query config' do
- it 'has the default order' do
- expect(event.order).to eq(event.start_time_attrs)
- end
- end
+ it_behaves_like 'default query config'
end
diff --git a/spec/lib/gitlab/cycle_analytics/review_event_fetcher_spec.rb b/spec/lib/gitlab/cycle_analytics/review_event_fetcher_spec.rb
index c3e66dcb861..4f67c95ed4c 100644
--- a/spec/lib/gitlab/cycle_analytics/review_event_fetcher_spec.rb
+++ b/spec/lib/gitlab/cycle_analytics/review_event_fetcher_spec.rb
@@ -4,9 +4,5 @@ require 'lib/gitlab/cycle_analytics/shared_event_spec'
describe Gitlab::CycleAnalytics::ReviewEventFetcher do
let(:stage_name) { :review }
- it_behaves_like 'default query config' do
- it 'has the default order' do
- expect(event.order).to eq(event.start_time_attrs)
- end
- end
+ it_behaves_like 'default query config'
end
diff --git a/spec/lib/gitlab/cycle_analytics/shared_event_spec.rb b/spec/lib/gitlab/cycle_analytics/shared_event_spec.rb
index 60ec87255c8..725f9a558f5 100644
--- a/spec/lib/gitlab/cycle_analytics/shared_event_spec.rb
+++ b/spec/lib/gitlab/cycle_analytics/shared_event_spec.rb
@@ -10,18 +10,10 @@ shared_examples 'default query config' do
let(:event) { described_class.new(fetcher: fetcher, options: {}, stage: stage_name) }
- it 'has the start attributes' do
- expect(event.start_time_attrs).not_to be_nil
- end
-
it 'has the stage attribute' do
expect(event.stage).not_to be_nil
end
- it 'has the end attributes' do
- expect(event.end_time_attrs).not_to be_nil
- end
-
it 'has the projection attributes' do
expect(event.projections).not_to be_nil
end
diff --git a/spec/lib/gitlab/cycle_analytics/shared_stage_spec.rb b/spec/lib/gitlab/cycle_analytics/shared_stage_spec.rb
index 8cc7875258e..c88e3e22f5c 100644
--- a/spec/lib/gitlab/cycle_analytics/shared_stage_spec.rb
+++ b/spec/lib/gitlab/cycle_analytics/shared_stage_spec.rb
@@ -8,6 +8,14 @@ shared_examples 'base stage' do
allow_any_instance_of(Gitlab::CycleAnalytics::BaseEventFetcher).to receive(:event_result).and_return({})
end
+ it 'has the start attributes' do
+ expect(stage.start_time_attrs).not_to be_nil
+ end
+
+ it 'has the end attributes' do
+ expect(stage.end_time_attrs).not_to be_nil
+ end
+
it 'has the median data value' do
expect(stage.median_data[:value]).not_to be_nil
end
diff --git a/spec/lib/gitlab/cycle_analytics/staging_event_fetcher_spec.rb b/spec/lib/gitlab/cycle_analytics/staging_event_fetcher_spec.rb
index 8338e17b96d..bbc82496340 100644
--- a/spec/lib/gitlab/cycle_analytics/staging_event_fetcher_spec.rb
+++ b/spec/lib/gitlab/cycle_analytics/staging_event_fetcher_spec.rb
@@ -5,8 +5,8 @@ describe Gitlab::CycleAnalytics::StagingEventFetcher do
let(:stage_name) { :staging }
it_behaves_like 'default query config' do
- it 'does not have the default order' do
- expect(event.order).not_to eq(event.start_time_attrs)
+ it 'has a default order' do
+ expect(event.order).not_to be_nil
end
end
end
diff --git a/spec/lib/gitlab/cycle_analytics/test_event_fetcher_spec.rb b/spec/lib/gitlab/cycle_analytics/test_event_fetcher_spec.rb
index 9d4f7667f1d..6639fa54e0e 100644
--- a/spec/lib/gitlab/cycle_analytics/test_event_fetcher_spec.rb
+++ b/spec/lib/gitlab/cycle_analytics/test_event_fetcher_spec.rb
@@ -5,8 +5,8 @@ describe Gitlab::CycleAnalytics::TestEventFetcher do
let(:stage_name) { :test }
it_behaves_like 'default query config' do
- it 'does not have the default order' do
- expect(event.order).not_to eq(event.start_time_attrs)
+ it 'has a default order' do
+ expect(event.order).not_to be_nil
end
end
end