diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/support/shared_examples/lib/gitlab | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/support/shared_examples/lib/gitlab')
8 files changed, 70 insertions, 25 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 a40c38106e2..af65b61021c 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 @@ -1,6 +1,6 @@ # frozen_string_literal: true -shared_examples 'resource mentions migration' do |migration_class, resource_class| +RSpec.shared_examples 'resource mentions migration' do |migration_class, resource_class| it 'migrates resource mentions' do join = migration_class::JOIN conditions = migration_class::QUERY_CONDITIONS @@ -21,7 +21,7 @@ shared_examples 'resource mentions migration' do |migration_class, resource_clas end end -shared_examples 'resource notes mentions migration' do |migration_class, resource_class| +RSpec.shared_examples 'resource notes mentions migration' do |migration_class, resource_class| it 'migrates mentions from note' do join = migration_class::JOIN conditions = migration_class::QUERY_CONDITIONS @@ -56,7 +56,7 @@ shared_examples 'resource notes mentions migration' do |migration_class, resourc end end -shared_examples 'schedules resource mentions migration' do |resource_class, is_for_notes| +RSpec.shared_examples 'schedules resource mentions migration' do |resource_class, is_for_notes| before do stub_const("#{described_class.name}::BATCH_SIZE", 1) end 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 index 14292f70228..d76089d56dd 100644 --- 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 @@ -4,7 +4,7 @@ require 'spec_helper' ISSUES_MEDIAN = 30.minutes.to_i -shared_examples 'base stage' do +RSpec.shared_examples 'base stage' do let(:stage) { described_class.new(options: { project: double }) } before do @@ -35,7 +35,7 @@ shared_examples 'base stage' do end end -shared_examples 'calculate #median with date range' do +RSpec.shared_examples 'calculate #median with date range' do context 'when valid date range is given' do before do stage_options[:from] = 5.days.ago @@ -55,7 +55,7 @@ shared_examples 'calculate #median with date range' do end end -shared_examples 'Gitlab::Analytics::CycleAnalytics::DataCollector backend examples' do +RSpec.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 }) } 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 index c053af010b3..4f648b27ea2 100644 --- 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 @@ -2,7 +2,7 @@ require 'spec_helper' -shared_examples 'default query config' do +RSpec.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 }) } 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..d0e41605e00 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 @@ -8,6 +8,7 @@ RSpec.shared_examples_for 'cycle analytics event' do 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) } + it { expect(instance.column_list).to be_a_kind_of(Array) } describe '#apply_query_customization' do it 'expects an ActiveRecord::Relation object as argument and returns a modified version of it' do diff --git a/spec/support/shared_examples/lib/gitlab/diff_file_collections_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/diff_file_collections_shared_examples.rb index a1cdd054f32..e43ce936b90 100644 --- a/spec/support/shared_examples/lib/gitlab/diff_file_collections_shared_examples.rb +++ b/spec/support/shared_examples/lib/gitlab/diff_file_collections_shared_examples.rb @@ -10,7 +10,7 @@ RSpec.shared_examples 'diff statistics' do |test_include_stats_flag: true| end end - context 'when should request diff stats' do + context 'when include_stats is true' do it 'Repository#diff_stats is called' do expect(diffable.project.repository) .to receive(:diff_stats) @@ -59,43 +59,87 @@ RSpec.shared_examples 'unfoldable diff' do end RSpec.shared_examples 'cacheable diff collection' do - let(:cache) { instance_double(Gitlab::Diff::HighlightCache) } + let(:highlight_cache) { instance_double(Gitlab::Diff::HighlightCache, write_if_empty: true, clear: nil, decorate: nil) } + let(:stats_cache) { instance_double(Gitlab::Diff::StatsCache, read: nil, write_if_empty: true, clear: nil) } before do - expect(Gitlab::Diff::HighlightCache).to receive(:new).with(subject) { cache } + expect(Gitlab::Diff::HighlightCache).to receive(:new).with(subject) { highlight_cache } end describe '#write_cache' do + before do + expect(Gitlab::Diff::StatsCache).to receive(:new).with(cachable_key: diffable.cache_key) { stats_cache } + end + it 'calls Gitlab::Diff::HighlightCache#write_if_empty' do - expect(cache).to receive(:write_if_empty).once + expect(highlight_cache).to receive(:write_if_empty).once + + subject.write_cache + end + + it 'calls Gitlab::Diff::StatsCache#write_if_empty with diff stats' do + diff_stats = Gitlab::Git::DiffStatsCollection.new([]) + + expect(diffable.project.repository) + .to receive(:diff_stats).and_return(diff_stats) + + expect(stats_cache).to receive(:write_if_empty).once.with(diff_stats) subject.write_cache end end describe '#clear_cache' do + before do + expect(Gitlab::Diff::StatsCache).to receive(:new).with(cachable_key: diffable.cache_key) { stats_cache } + end + it 'calls Gitlab::Diff::HighlightCache#clear' do - expect(cache).to receive(:clear).once + expect(highlight_cache).to receive(:clear).once subject.clear_cache end - end - describe '#cache_key' do - it 'calls Gitlab::Diff::HighlightCache#key' do - expect(cache).to receive(:key).once + it 'calls Gitlab::Diff::StatsCache#clear' do + expect(stats_cache).to receive(:clear).once - subject.cache_key + subject.clear_cache end end describe '#diff_files' do + before do + expect(Gitlab::Diff::StatsCache).to receive(:new).with(cachable_key: diffable.cache_key) { stats_cache } + end + it 'calls Gitlab::Diff::HighlightCache#decorate' do - expect(cache).to receive(:decorate) + expect(highlight_cache).to receive(:decorate) .with(instance_of(Gitlab::Diff::File)) .exactly(cacheable_files_count).times subject.diff_files end + + context 'when there are stats cached' do + before do + allow(stats_cache).to receive(:read).and_return(Gitlab::Git::DiffStatsCollection.new([])) + end + + it 'does not make a diff stats rpc call' do + expect(diffable.project.repository).not_to receive(:diff_stats) + + subject.diff_files + end + end + + context 'when there are no stats cached' do + it 'makes a diff stats rpc call' do + expect(diffable.project.repository) + .to receive(:diff_stats) + .with(diffable.diff_refs.base_sha, diffable.diff_refs.head_sha) + + subject.diff_files + end + end end end diff --git a/spec/support/shared_examples/lib/gitlab/gl_repository_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/gl_repository_shared_examples.rb index 97f4341340d..28137530038 100644 --- a/spec/support/shared_examples/lib/gitlab/gl_repository_shared_examples.rb +++ b/spec/support/shared_examples/lib/gitlab/gl_repository_shared_examples.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true RSpec.shared_examples 'parsing gl_repository identifier' do - subject { described_class.new(identifier) } + subject { described_class.parse(identifier) } it 'returns correct information' do - aggregate_failures do - expect(subject.repo_type).to eq(expected_type) - expect(subject.fetch_container!).to eq(expected_container) - end + expect(subject).to have_attributes( + repo_type: expected_type, + container: expected_container + ) end end diff --git a/spec/support/shared_examples/lib/gitlab/import/stuck_import_job_workers_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/import/stuck_import_job_workers_shared_examples.rb index 06ea540706a..222390cf9cd 100644 --- a/spec/support/shared_examples/lib/gitlab/import/stuck_import_job_workers_shared_examples.rb +++ b/spec/support/shared_examples/lib/gitlab/import/stuck_import_job_workers_shared_examples.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -shared_examples 'stuck import job detection' do +RSpec.shared_examples 'stuck import job detection' do context 'when the job has completed' do context 'when the import status was already updated' do before do diff --git a/spec/support/shared_examples/lib/gitlab/jira_import/base_importer_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/jira_import/base_importer_shared_examples.rb index 85dcc053447..b1788bb5912 100644 --- a/spec/support/shared_examples/lib/gitlab/jira_import/base_importer_shared_examples.rb +++ b/spec/support/shared_examples/lib/gitlab/jira_import/base_importer_shared_examples.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -shared_examples 'raise exception if not implemented' do +RSpec.shared_examples 'raise exception if not implemented' do it { expect { described_class.new(project).imported_items_cache_key }.not_to raise_error } end |