From 6763d2787670bc03a36a8eb601703e88fc70dece Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 18 Mar 2020 09:09:31 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- .../mentions_migration_shared_examples.rb | 8 --- .../cycle_analytics/base_stage_shared_examples.rb | 74 ++++++++++++++++++++++ .../default_query_config_shared_examples.rb | 16 +++++ .../cycle_analytics/event_shared_examples.rb | 20 ++++++ .../cycle_analytics_event_shared_examples.rb | 20 ------ 5 files changed, 110 insertions(+), 28 deletions(-) create mode 100644 spec/support/shared_examples/lib/gitlab/cycle_analytics/base_stage_shared_examples.rb create mode 100644 spec/support/shared_examples/lib/gitlab/cycle_analytics/default_query_config_shared_examples.rb create mode 100644 spec/support/shared_examples/lib/gitlab/cycle_analytics/event_shared_examples.rb delete mode 100644 spec/support/shared_examples/lib/gitlab/cycle_analytics_event_shared_examples.rb (limited to 'spec/support/shared_examples/lib') diff --git a/spec/support/shared_examples/lib/gitlab/background_migration/mentions_migration_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/background_migration/mentions_migration_shared_examples.rb index a3f0c84bd1f..a40c38106e2 100644 --- a/spec/support/shared_examples/lib/gitlab/background_migration/mentions_migration_shared_examples.rb +++ b/spec/support/shared_examples/lib/gitlab/background_migration/mentions_migration_shared_examples.rb @@ -22,14 +22,6 @@ shared_examples 'resource mentions migration' do |migration_class, resource_clas end shared_examples 'resource notes mentions migration' do |migration_class, resource_class| - before do - note1.becomes(Note).save! - note2.becomes(Note).save! - note3.becomes(Note).save! - note4.becomes(Note).save! - note5.becomes(Note).save(validate: false) - end - it 'migrates mentions from note' do join = migration_class::JOIN conditions = migration_class::QUERY_CONDITIONS diff --git a/spec/support/shared_examples/lib/gitlab/cycle_analytics/base_stage_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/cycle_analytics/base_stage_shared_examples.rb new file mode 100644 index 00000000000..851ed9c65a3 --- /dev/null +++ b/spec/support/shared_examples/lib/gitlab/cycle_analytics/base_stage_shared_examples.rb @@ -0,0 +1,74 @@ +# frozen_string_literal: true + +require 'spec_helper' + +ISSUES_MEDIAN = 30.minutes.to_i + +shared_examples 'base stage' do + let(:stage) { described_class.new(options: { project: double }) } + + before do + allow(stage).to receive(:project_median).and_return(1.12) + allow_next_instance_of(Gitlab::CycleAnalytics::BaseEventFetcher) do |instance| + allow(instance).to receive(:event_result).and_return({}) + end + end + + it 'has the median data value' do + expect(stage.as_json[:value]).not_to be_nil + end + + it 'has the median data stage' do + expect(stage.as_json[:title]).not_to be_nil + end + + it 'has the median data description' do + expect(stage.as_json[:description]).not_to be_nil + end + + it 'has the title' do + expect(stage.title).to eq(stage_name.to_s.capitalize) + end + + it 'has the events' do + expect(stage.events).not_to be_nil + end +end + +shared_examples 'calculate #median with date range' do + context 'when valid date range is given' do + before do + stage_options[:from] = 5.days.ago + stage_options[:to] = 5.days.from_now + end + + it { expect(stage.project_median).to eq(ISSUES_MEDIAN) } + end + + context 'when records are out of the date range' do + before do + stage_options[:from] = 2.years.ago + stage_options[:to] = 1.year.ago + end + + it { expect(stage.project_median).to eq(nil) } + end +end + +shared_examples 'Gitlab::Analytics::CycleAnalytics::DataCollector backend examples' do + let(:stage_params) { Gitlab::Analytics::CycleAnalytics::DefaultStages.send("params_for_#{stage_name}_stage").merge(project: project) } + let(:stage) { Analytics::CycleAnalytics::ProjectStage.new(stage_params) } + let(:data_collector) { Gitlab::Analytics::CycleAnalytics::DataCollector.new(stage: stage, params: { from: stage_options[:from], current_user: project.creator }) } + let(:attribute_to_verify) { :title } + + context 'provides the same results as the old implementation' do + it 'for the median' do + expect(data_collector.median.seconds).to eq(ISSUES_MEDIAN) + end + + it 'for the list of event records' do + records = data_collector.records_fetcher.serialized_records + expect(records.map { |event| event[attribute_to_verify] }).to eq(expected_ordered_attribute_values) + end + end +end diff --git a/spec/support/shared_examples/lib/gitlab/cycle_analytics/default_query_config_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/cycle_analytics/default_query_config_shared_examples.rb new file mode 100644 index 00000000000..c053af010b3 --- /dev/null +++ b/spec/support/shared_examples/lib/gitlab/cycle_analytics/default_query_config_shared_examples.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require 'spec_helper' + +shared_examples 'default query config' do + let(:project) { create(:project) } + let(:event) { described_class.new(stage: stage_name, options: { from: 1.day.ago, project: project }) } + + it 'has the stage attribute' do + expect(event.stage).not_to be_nil + end + + it 'has the projection attributes' do + expect(event.projections).not_to be_nil + end +end diff --git a/spec/support/shared_examples/lib/gitlab/cycle_analytics/event_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/cycle_analytics/event_shared_examples.rb new file mode 100644 index 00000000000..a00359ce979 --- /dev/null +++ b/spec/support/shared_examples/lib/gitlab/cycle_analytics/event_shared_examples.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +RSpec.shared_examples_for 'cycle analytics event' do + let(:params) { {} } + let(:instance) { described_class.new(params) } + + it { expect(described_class.name).to be_a_kind_of(String) } + it { expect(described_class.identifier).to be_a_kind_of(Symbol) } + it { expect(instance.object_type.ancestors).to include(ApplicationRecord) } + it { expect(instance).to respond_to(:timestamp_projection) } + + describe '#apply_query_customization' do + it 'expects an ActiveRecord::Relation object as argument and returns a modified version of it' do + input_query = instance.object_type.all + + output_query = instance.apply_query_customization(input_query) + expect(output_query).to be_a_kind_of(ActiveRecord::Relation) + end + end +end diff --git a/spec/support/shared_examples/lib/gitlab/cycle_analytics_event_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/cycle_analytics_event_shared_examples.rb deleted file mode 100644 index a00359ce979..00000000000 --- a/spec/support/shared_examples/lib/gitlab/cycle_analytics_event_shared_examples.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -RSpec.shared_examples_for 'cycle analytics event' do - let(:params) { {} } - let(:instance) { described_class.new(params) } - - it { expect(described_class.name).to be_a_kind_of(String) } - it { expect(described_class.identifier).to be_a_kind_of(Symbol) } - it { expect(instance.object_type.ancestors).to include(ApplicationRecord) } - it { expect(instance).to respond_to(:timestamp_projection) } - - describe '#apply_query_customization' do - it 'expects an ActiveRecord::Relation object as argument and returns a modified version of it' do - input_query = instance.object_type.all - - output_query = instance.apply_query_customization(input_query) - expect(output_query).to be_a_kind_of(ActiveRecord::Relation) - end - end -end -- cgit v1.2.1