Commit a67311cb authored by James Lopez's avatar James Lopez

Fix other spec failures

parent 02e1e481
module CycleAnalyticsParams module CycleAnalyticsParams
extend ActiveSupport::Concern extend ActiveSupport::Concern
def options def options(params)
@options ||= { from: start_date(events_params), current_user: current_user } @options ||= { from: start_date(params), current_user: current_user }
end end
def start_date(params) def start_date(params)
......
...@@ -9,46 +9,46 @@ module Projects ...@@ -9,46 +9,46 @@ module Projects
before_action :authorize_read_merge_request!, only: [:code, :review] before_action :authorize_read_merge_request!, only: [:code, :review]
def issue def issue
render_events(events.issue_events) render_events(cycle_analytics.events_for(:issue))
end end
def plan def plan
render_events(events.plan_events) render_events(cycle_analytics.events_for(:plan))
end end
def code def code
render_events(events.code_events) render_events(cycle_analytics.events_for(:code))
end end
def test def test
options[:branch] = events_params[:branch_name] options(events_params)[:branch] = events_params[:branch_name]
render_events(events.test_events) render_events(cycle_analytics.events_for(:test))
end end
def review def review
render_events(events.review_events) render_events(cycle_analytics.events_for(:review))
end end
def staging def staging
render_events(events.staging_events) render_events(cycle_analytics.events_for(:staging))
end end
def production def production
render_events(events.production_events) render_events(cycle_analytics.events_for(:production))
end end
private private
def render_events(events_list) def render_events(events)
respond_to do |format| respond_to do |format|
format.html format.html
format.json { render json: { events: events_list } } format.json { render json: { events: events } }
end end
end end
def events def cycle_analytics
@events ||= Gitlab::CycleAnalytics::Events.new(project: project, options: options) @cycle_analytics ||= ::CycleAnalytics.new(project, options: options(events_params))
end end
def events_params def events_params
......
...@@ -6,7 +6,7 @@ class Projects::CycleAnalyticsController < Projects::ApplicationController ...@@ -6,7 +6,7 @@ class Projects::CycleAnalyticsController < Projects::ApplicationController
before_action :authorize_read_cycle_analytics! before_action :authorize_read_cycle_analytics!
def show def show
@cycle_analytics = ::CycleAnalytics.new(@project, options: options) @cycle_analytics = ::CycleAnalytics.new(@project, options: options(cycle_analytics_params))
@cycle_analytics_no_data = @cycle_analytics.no_stats? @cycle_analytics_no_data = @cycle_analytics.no_stats?
...@@ -21,7 +21,7 @@ class Projects::CycleAnalyticsController < Projects::ApplicationController ...@@ -21,7 +21,7 @@ class Projects::CycleAnalyticsController < Projects::ApplicationController
def cycle_analytics_params def cycle_analytics_params
return {} unless params[:cycle_analytics].present? return {} unless params[:cycle_analytics].present?
{ start_date: params[:cycle_analytics][:start_date] } params[:cycle_analytics].slice(:start_date)
end end
def cycle_analytics_json def cycle_analytics_json
......
...@@ -7,7 +7,7 @@ class CycleAnalytics ...@@ -7,7 +7,7 @@ class CycleAnalytics
end end
def summary def summary
@summary ||= Gitlab::CycleAnalytics::Summary.new(@project, from: @options[:from]).data @summary ||= ::Gitlab::CycleAnalytics::StageSummary.new(@project, from: @options[:from]).data
end end
def stats def stats
...@@ -15,23 +15,26 @@ class CycleAnalytics ...@@ -15,23 +15,26 @@ class CycleAnalytics
end end
def no_stats? def no_stats?
stats.map(&:value).compact.empty? stats.map { |hash| hash[:value] }.compact.empty?
end end
def permissions(user:) def permissions(user:)
Gitlab::CycleAnalytics::Permissions.get(user: user, project: @project) Gitlab::CycleAnalytics::Permissions.get(user: user, project: @project)
end end
def events_for(stage)
classify_stage(stage).new(project: @project, options: @options, stage: stage).events
end
private private
def stats_per_stage def stats_per_stage
STAGES.map do |stage_name| STAGES.map do |stage_name|
classify_stage(method_sym).new(project: @project, options: @options, stage: stage_name).median_data classify_stage(stage_name).new(project: @project, options: @options, stage: stage_name).median_data
end end
end end
def classify_stage(stage_name) def classify_stage(stage_name)
"Gitlab::CycleAnalytics::#{stage_name.to_s.capitalize}Stage".constantize "Gitlab::CycleAnalytics::#{stage_name.to_s.capitalize}Stage".constantize
end end
end end
...@@ -5,10 +5,11 @@ module Gitlab ...@@ -5,10 +5,11 @@ module Gitlab
attr_reader :stage, :start_time_attrs, :end_time_attrs, :projections, :query attr_reader :stage, :start_time_attrs, :end_time_attrs, :projections, :query
def initialize(fetcher:, stage:) def initialize(fetcher:, stage:, options:)
@query = EventsQuery.new(fetcher: fetcher) @query = EventsQuery.new(fetcher: fetcher)
@project = fetcher.project @project = fetcher.project
@stage = stage @stage = stage
@options = options
end end
def fetch def fetch
......
...@@ -13,7 +13,7 @@ module Gitlab ...@@ -13,7 +13,7 @@ module Gitlab
end end
def events def events
event_class.new(fetcher: @fetcher, stage: @stage).fetch event_class.new(fetcher: @fetcher, stage: @stage, options: @options).fetch
end end
def median_data def median_data
......
module Gitlab
module CycleAnalytics
class Events
def initialize(project:, options:)
@project = project
@options = options
end
def issue_events
IssueEvent.new(project: @project, options: @options).fetch
end
def plan_events
PlanEvent.new(project: @project, options: @options).fetch
end
def code_events
CodeEvent.new(project: @project, options: @options).fetch
end
def test_events
TestEvent.new(project: @project, options: @options).fetch
end
def review_events
ReviewEvent.new(project: @project, options: @options).fetch
end
def staging_events
StagingEvent.new(project: @project, options: @options).fetch
end
def production_events
ProductionEvent.new(project: @project, options: @options).fetch
end
end
end
end
module Gitlab module Gitlab
module CycleAnalytics module CycleAnalytics
module Summary class StageSummary
extend self
def initialize(project, from:) def initialize(project, from:)
@project = project @project = project
@from = from @from = from
......
...@@ -8,7 +8,7 @@ module Gitlab ...@@ -8,7 +8,7 @@ module Gitlab
end end
def title def title
self.name self.class.name.demodulize
end end
def value def value
......
...@@ -2,6 +2,8 @@ require 'spec_helper' ...@@ -2,6 +2,8 @@ require 'spec_helper'
require 'lib/gitlab/cycle_analytics/shared_event_spec' require 'lib/gitlab/cycle_analytics/shared_event_spec'
describe Gitlab::CycleAnalytics::CodeEvent do describe Gitlab::CycleAnalytics::CodeEvent do
let(:stage_name) { :code }
it_behaves_like 'default query config' do it_behaves_like 'default query config' do
it 'does not have the default order' do it 'does not have the default order' do
expect(event.order).not_to eq(event.start_time_attrs) expect(event.order).not_to eq(event.start_time_attrs)
......
...@@ -2,6 +2,8 @@ require 'spec_helper' ...@@ -2,6 +2,8 @@ require 'spec_helper'
require 'lib/gitlab/cycle_analytics/shared_event_spec' require 'lib/gitlab/cycle_analytics/shared_event_spec'
describe Gitlab::CycleAnalytics::IssueEvent do describe Gitlab::CycleAnalytics::IssueEvent do
let(:stage_name) { :issue }
it_behaves_like 'default query config' do it_behaves_like 'default query config' do
it 'has the default order' do it 'has the default order' do
expect(event.order).to eq(event.start_time_attrs) expect(event.order).to eq(event.start_time_attrs)
......
...@@ -2,6 +2,8 @@ require 'spec_helper' ...@@ -2,6 +2,8 @@ require 'spec_helper'
require 'lib/gitlab/cycle_analytics/shared_event_spec' require 'lib/gitlab/cycle_analytics/shared_event_spec'
describe Gitlab::CycleAnalytics::PlanEvent do describe Gitlab::CycleAnalytics::PlanEvent do
let(:stage_name) { :plan }
it_behaves_like 'default query config' do it_behaves_like 'default query config' do
it 'has the default order' do it 'has the default order' do
expect(event.order).to eq(event.start_time_attrs) expect(event.order).to eq(event.start_time_attrs)
......
...@@ -2,6 +2,8 @@ require 'spec_helper' ...@@ -2,6 +2,8 @@ require 'spec_helper'
require 'lib/gitlab/cycle_analytics/shared_event_spec' require 'lib/gitlab/cycle_analytics/shared_event_spec'
describe Gitlab::CycleAnalytics::ProductionEvent do describe Gitlab::CycleAnalytics::ProductionEvent do
let(:stage_name) { :production }
it_behaves_like 'default query config' do it_behaves_like 'default query config' do
it 'has the default order' do it 'has the default order' do
expect(event.order).to eq(event.start_time_attrs) expect(event.order).to eq(event.start_time_attrs)
......
...@@ -2,6 +2,8 @@ require 'spec_helper' ...@@ -2,6 +2,8 @@ require 'spec_helper'
require 'lib/gitlab/cycle_analytics/shared_event_spec' require 'lib/gitlab/cycle_analytics/shared_event_spec'
describe Gitlab::CycleAnalytics::ReviewEvent do describe Gitlab::CycleAnalytics::ReviewEvent do
let(:stage_name) { :review }
it_behaves_like 'default query config' do it_behaves_like 'default query config' do
it 'has the default order' do it 'has the default order' do
expect(event.order).to eq(event.start_time_attrs) expect(event.order).to eq(event.start_time_attrs)
......
require 'spec_helper' require 'spec_helper'
shared_examples 'default query config' do shared_examples 'default query config' do
let(:event) { described_class.new(project: double, options: {}) } let(:fetcher) do
Gitlab::CycleAnalytics::MetricsFetcher.new(project: create(:empty_project),
from: 1.day.ago,
branch: nil)
end
let(:event) { described_class.new(fetcher: fetcher, stage: stage_name, options: {}) }
it 'has the start attributes' do it 'has the start attributes' do
expect(event.start_time_attrs).not_to be_nil expect(event.start_time_attrs).not_to be_nil
......
...@@ -2,6 +2,8 @@ require 'spec_helper' ...@@ -2,6 +2,8 @@ require 'spec_helper'
require 'lib/gitlab/cycle_analytics/shared_event_spec' require 'lib/gitlab/cycle_analytics/shared_event_spec'
describe Gitlab::CycleAnalytics::StagingEvent do describe Gitlab::CycleAnalytics::StagingEvent do
let(:stage_name) { :staging }
it_behaves_like 'default query config' do it_behaves_like 'default query config' do
it 'does not have the default order' do it 'does not have the default order' do
expect(event.order).not_to eq(event.start_time_attrs) expect(event.order).not_to eq(event.start_time_attrs)
......
...@@ -2,6 +2,8 @@ require 'spec_helper' ...@@ -2,6 +2,8 @@ require 'spec_helper'
require 'lib/gitlab/cycle_analytics/shared_event_spec' require 'lib/gitlab/cycle_analytics/shared_event_spec'
describe Gitlab::CycleAnalytics::TestEvent do describe Gitlab::CycleAnalytics::TestEvent do
let(:stage_name) { :test }
it_behaves_like 'default query config' do it_behaves_like 'default query config' do
it 'does not have the default order' do it 'does not have the default order' do
expect(event.order).not_to eq(event.start_time_attrs) expect(event.order).not_to eq(event.start_time_attrs)
......
require 'spec_helper' require 'spec_helper'
describe CycleAnalytics::Summary, models: true do describe Gitlab::CycleAnalytics::StageSummary, models: true do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:from) { Time.now } let(:from) { Time.now }
let(:user) { create(:user, :admin) } let(:user) { create(:user, :admin) }
......
...@@ -8,10 +8,10 @@ describe AnalyticsSummarySerializer do ...@@ -8,10 +8,10 @@ describe AnalyticsSummarySerializer do
let(:json) { serializer.as_json } let(:json) { serializer.as_json }
let(:project) { create(:empty_project) } let(:project) { create(:empty_project) }
let(:resource) { Gitlab::CycleAnalytics::Summary::Issue.new(project: double, from: 1.day.ago) } let(:resource) { Gitlab::CycleAnalytics::StageSummary::Issue.new(project: double, from: 1.day.ago) }
before do before do
allow_any_instance_of(Gitlab::CycleAnalytics::Summary::Issue).to receive(:value).and_return(1.12) allow_any_instance_of(Gitlab::CycleAnalytics::StageSummary::Issue).to receive(:value).and_return(1.12)
end end
it 'it generates payload for single object' do it 'it generates payload for single object' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment