diff options
author | James Lopez <james@jameslopez.es> | 2016-11-23 13:28:28 +0300 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2017-01-17 13:32:55 +0300 |
commit | a67311cb4c9f54af43d300fde5240f9a370193d1 (patch) | |
tree | 14b82a6181b6cd7a148eeda9d2e50002c798dd8e /app | |
parent | 02e1e4819234662faddd7d8eb5c54d9bfdf9e7e6 (diff) |
Fix other spec failures
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/concerns/cycle_analytics_params.rb | 4 | ||||
-rw-r--r-- | app/controllers/projects/cycle_analytics/events_controller.rb | 26 | ||||
-rw-r--r-- | app/controllers/projects/cycle_analytics_controller.rb | 4 | ||||
-rw-r--r-- | app/models/cycle_analytics.rb | 11 |
4 files changed, 24 insertions, 21 deletions
diff --git a/app/controllers/concerns/cycle_analytics_params.rb b/app/controllers/concerns/cycle_analytics_params.rb index 91456561a17..52e06f4945a 100644 --- a/app/controllers/concerns/cycle_analytics_params.rb +++ b/app/controllers/concerns/cycle_analytics_params.rb @@ -1,8 +1,8 @@ module CycleAnalyticsParams extend ActiveSupport::Concern - def options - @options ||= { from: start_date(events_params), current_user: current_user } + def options(params) + @options ||= { from: start_date(params), current_user: current_user } end def start_date(params) diff --git a/app/controllers/projects/cycle_analytics/events_controller.rb b/app/controllers/projects/cycle_analytics/events_controller.rb index 5e9524b15db..e571e1dfce2 100644 --- a/app/controllers/projects/cycle_analytics/events_controller.rb +++ b/app/controllers/projects/cycle_analytics/events_controller.rb @@ -9,46 +9,46 @@ module Projects before_action :authorize_read_merge_request!, only: [:code, :review] def issue - render_events(events.issue_events) + render_events(cycle_analytics.events_for(:issue)) end def plan - render_events(events.plan_events) + render_events(cycle_analytics.events_for(:plan)) end def code - render_events(events.code_events) + render_events(cycle_analytics.events_for(:code)) end 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 def review - render_events(events.review_events) + render_events(cycle_analytics.events_for(:review)) end def staging - render_events(events.staging_events) + render_events(cycle_analytics.events_for(:staging)) end def production - render_events(events.production_events) + render_events(cycle_analytics.events_for(:production)) end private - - def render_events(events_list) + + def render_events(events) respond_to do |format| format.html - format.json { render json: { events: events_list } } + format.json { render json: { events: events } } end end - def events - @events ||= Gitlab::CycleAnalytics::Events.new(project: project, options: options) + def cycle_analytics + @cycle_analytics ||= ::CycleAnalytics.new(project, options: options(events_params)) end def events_params diff --git a/app/controllers/projects/cycle_analytics_controller.rb b/app/controllers/projects/cycle_analytics_controller.rb index 93dbe2819e7..cf53d0a1919 100644 --- a/app/controllers/projects/cycle_analytics_controller.rb +++ b/app/controllers/projects/cycle_analytics_controller.rb @@ -6,7 +6,7 @@ class Projects::CycleAnalyticsController < Projects::ApplicationController before_action :authorize_read_cycle_analytics! 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? @@ -21,7 +21,7 @@ class Projects::CycleAnalyticsController < Projects::ApplicationController def cycle_analytics_params return {} unless params[:cycle_analytics].present? - { start_date: params[:cycle_analytics][:start_date] } + params[:cycle_analytics].slice(:start_date) end def cycle_analytics_json diff --git a/app/models/cycle_analytics.rb b/app/models/cycle_analytics.rb index 00e9f7c7d5c..5bcc6fa1954 100644 --- a/app/models/cycle_analytics.rb +++ b/app/models/cycle_analytics.rb @@ -7,7 +7,7 @@ class CycleAnalytics end def summary - @summary ||= Gitlab::CycleAnalytics::Summary.new(@project, from: @options[:from]).data + @summary ||= ::Gitlab::CycleAnalytics::StageSummary.new(@project, from: @options[:from]).data end def stats @@ -15,23 +15,26 @@ class CycleAnalytics end def no_stats? - stats.map(&:value).compact.empty? + stats.map { |hash| hash[:value] }.compact.empty? end def permissions(user:) Gitlab::CycleAnalytics::Permissions.get(user: user, project: @project) end + def events_for(stage) + classify_stage(stage).new(project: @project, options: @options, stage: stage).events + end + private def stats_per_stage 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 def classify_stage(stage_name) "Gitlab::CycleAnalytics::#{stage_name.to_s.capitalize}Stage".constantize end - end |