Commit dc6ea14b authored by James Lopez's avatar James Lopez

fixed stage entity and added missing stage specs

parent a9982762
......@@ -2,11 +2,11 @@ class AnalyticsStageEntity < Grape::Entity
include EntityDateHelper
expose :stage, as: :title do |object|
object[:stage].to_s.capitalize
object.stage.to_s.capitalize
end
expose :description
expose :median, as: :value do |stage|
stage[:median] && !stage[:median].zero? ? distance_of_time_in_words(stage[:median]) : nil
stage.median && !stage.median.zero? ? distance_of_time_in_words(stage.median) : nil
end
end
......@@ -3,7 +3,7 @@ module Gitlab
class BaseStage
attr_reader :stage, :description
def initialize(project:, options:, stage: stage)
def initialize(project:, options:, stage:)
@project = project
@options = options
@fetcher = Gitlab::CycleAnalytics::MetricsFetcher.new(project: project,
......@@ -16,6 +16,10 @@ module Gitlab
event_class.new(fetcher: @fetcher, stage: @stage).fetch
end
def median_data
AnalyticsStageSerializer.new.represent(self).as_json
end
private
def event_class
......
require 'spec_helper'
require 'lib/gitlab/cycle_analytics/shared_stage_spec'
describe Gitlab::CycleAnalytics::CodeStage do
let(:stage_name) { :code }
it_behaves_like 'base stage'
end
require 'spec_helper'
require 'lib/gitlab/cycle_analytics/shared_stage_spec'
describe Gitlab::CycleAnalytics::IssueStage do
let(:stage_name) { :issue }
it_behaves_like 'base stage'
end
require 'spec_helper'
require 'lib/gitlab/cycle_analytics/shared_stage_spec'
describe Gitlab::CycleAnalytics::PlanStage do
let(:stage_name) { :plan }
it_behaves_like 'base stage'
end
require 'spec_helper'
require 'lib/gitlab/cycle_analytics/shared_stage_spec'
describe Gitlab::CycleAnalytics::ProductionStage do
let(:stage_name) { :production }
it_behaves_like 'base stage'
end
require 'spec_helper'
require 'lib/gitlab/cycle_analytics/shared_stage_spec'
describe Gitlab::CycleAnalytics::ReviewStage do
let(:stage_name) { :review }
it_behaves_like 'base stage'
end
require 'spec_helper'
shared_examples 'base stage' do
let(:stage) { described_class.new(project: double, options: {}, stage: stage_name) }
before do
allow_any_instance_of(Gitlab::CycleAnalytics::MetricsFetcher).to receive(:calculate_metric).and_return(1.12)
allow_any_instance_of(Gitlab::CycleAnalytics::BaseEvent).to receive(:event_result).and_return({})
end
it 'has the median data value' do
expect(stage.median_data[:value]).not_to be_nil
end
it 'has the median data stage' do
expect(stage.median_data[:title]).not_to be_nil
end
it 'has the median data description' do
expect(stage.median_data[:description]).not_to be_nil
end
it 'has the stage' do
expect(stage.stage).to eq(stage_name)
end
it 'has the events' do
expect(stage.events).not_to be_nil
end
end
require 'spec_helper'
require 'lib/gitlab/cycle_analytics/shared_stage_spec'
describe Gitlab::CycleAnalytics::StagingStage do
let(:stage_name) { :staging }
it_behaves_like 'base stage'
end
require 'spec_helper'
require 'lib/gitlab/cycle_analytics/shared_stage_spec'
describe Gitlab::CycleAnalytics::TestStage do
let(:stage_name) { :test }
it_behaves_like 'base stage'
end
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