diff options
author | James Lopez <james@jameslopez.es> | 2016-11-21 15:39:43 +0100 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2016-11-21 17:19:18 +0100 |
commit | dde8fba524aa071d08121818a1e2c3d635664819 (patch) | |
tree | 461c9a555c110fcae9687b041dccdd9c70df9a11 | |
parent | 80eaed1651e6a278af87e015f6b414d4f943a352 (diff) | |
download | gitlab-ce-dde8fba524aa071d08121818a1e2c3d635664819.tar.gz |
Adds a flag to reflect whether or not there is data in cycle analytics
-rw-r--r-- | app/controllers/projects/cycle_analytics_controller.rb | 24 | ||||
-rw-r--r-- | spec/controllers/projects/cycle_analytics_controller_spec.rb | 43 |
2 files changed, 62 insertions, 5 deletions
diff --git a/app/controllers/projects/cycle_analytics_controller.rb b/app/controllers/projects/cycle_analytics_controller.rb index 00ecdcbd1b9..b75b391b461 100644 --- a/app/controllers/projects/cycle_analytics_controller.rb +++ b/app/controllers/projects/cycle_analytics_controller.rb @@ -8,6 +8,10 @@ class Projects::CycleAnalyticsController < Projects::ApplicationController def show @cycle_analytics = ::CycleAnalytics.new(@project, from: start_date(cycle_analytics_params)) + stats_values, cycle_analytics_json = generate_cycle_analytics_json + + @cycle_analytics_not_set_up = stats_with_no_data?(stats_values) + respond_to do |format| format.html format.json { render json: cycle_analytics_json } @@ -22,7 +26,9 @@ class Projects::CycleAnalyticsController < Projects::ApplicationController { start_date: params[:cycle_analytics][:start_date] } end - def cycle_analytics_json + def generate_cycle_analytics_json + stats_values = [] + cycle_analytics_view_data = [[:issue, "Issue", "Time before an issue gets scheduled"], [:plan, "Plan", "Time before an issue starts implementation"], [:code, "Code", "Time until first merge request"], @@ -34,11 +40,14 @@ class Projects::CycleAnalyticsController < Projects::ApplicationController stats = cycle_analytics_view_data.reduce([]) do |stats, (stage_method, stage_text, stage_description)| value = @cycle_analytics.send(stage_method).presence + stats_values << value.abs if value + stats << { title: stage_text, description: stage_description, value: value && !value.zero? ? distance_of_time_in_words(value) : nil } + stats end @@ -52,10 +61,15 @@ class Projects::CycleAnalyticsController < Projects::ApplicationController { title: "Deploy".pluralize(deploys), value: deploys } ] - { - summary: summary, - stats: stats, - permissions: @cycle_analytics.permissions(user: current_user) + cycle_analytics_hash = { summary: summary, + stats: stats, + permissions: @cycle_analytics.permissions(user: current_user) } + + [stats_values, cycle_analytics_hash] + end + + def stats_with_no_data?(stats_values) + stats_values.blank? || stats_values.inject(:+).zero? end end diff --git a/spec/controllers/projects/cycle_analytics_controller_spec.rb b/spec/controllers/projects/cycle_analytics_controller_spec.rb new file mode 100644 index 00000000000..9131014a05d --- /dev/null +++ b/spec/controllers/projects/cycle_analytics_controller_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper' + +describe Projects::CycleAnalyticsController do + let(:project) { create(:project) } + let(:user) { create(:user) } + + before do + sign_in(user) + project.team << [user, :master] + end + + describe 'cycle analytics not set up flag' do + context 'with no data' do + it 'is true' do + get(:show, + namespace_id: project.namespace.to_param, + project_id: project.to_param) + + expect(response).to be_success + expect(assigns(:cycle_analytics_not_set_up)).to eq(true) + end + end + + context 'with data' do + before do + issue = create(:issue, project: project, created_at: 4.days.ago) + milestone = create(:milestone, project: project, created_at: 5.days.ago) + issue.update(milestone: milestone) + + create_merge_request_closing_issue(issue) + end + + it 'is false' do + get(:show, + namespace_id: project.namespace.to_param, + project_id: project.to_param) + + expect(response).to be_success + expect(assigns(:cycle_analytics_not_set_up)).to eq(false) + end + end + end +end |