diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-18 12:09:31 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-18 12:09:31 +0300 |
commit | 6763d2787670bc03a36a8eb601703e88fc70dece (patch) | |
tree | edc653ffd3052e3f9898c4fa8a07621d51574767 /spec/support | |
parent | ed9165c2abda1dca048a8d3cb8030d906c0bbb0c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support')
-rw-r--r-- | spec/support/shared_examples/lib/gitlab/background_migration/mentions_migration_shared_examples.rb | 8 | ||||
-rw-r--r-- | spec/support/shared_examples/lib/gitlab/cycle_analytics/base_stage_shared_examples.rb | 74 | ||||
-rw-r--r-- | spec/support/shared_examples/lib/gitlab/cycle_analytics/default_query_config_shared_examples.rb | 16 | ||||
-rw-r--r-- | spec/support/shared_examples/lib/gitlab/cycle_analytics/event_shared_examples.rb (renamed from spec/support/shared_examples/lib/gitlab/cycle_analytics_event_shared_examples.rb) | 0 |
4 files changed, 90 insertions, 8 deletions
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 index a00359ce979..a00359ce979 100644 --- 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 |