diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-20 16:37:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-20 16:37:47 +0300 |
commit | aee0a117a889461ce8ced6fcf73207fe017f1d99 (patch) | |
tree | 891d9ef189227a8445d83f35c1b0fc99573f4380 /spec/support/shared_examples/lib | |
parent | 8d46af3258650d305f53b819eabf7ab18d22f59e (diff) |
Add latest changes from gitlab-org/gitlab@14-6-stable-eev14.6.0-rc42
Diffstat (limited to 'spec/support/shared_examples/lib')
4 files changed, 49 insertions, 114 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 deleted file mode 100644 index 7707e79386c..00000000000 --- a/spec/support/shared_examples/lib/gitlab/background_migration/mentions_migration_shared_examples.rb +++ /dev/null @@ -1,108 +0,0 @@ -# frozen_string_literal: true - -RSpec.shared_examples 'resource mentions migration' do |migration_class, resource_class_name| - it 'migrates resource mentions' do - join = migration_class::JOIN - conditions = migration_class::QUERY_CONDITIONS - resource_class = "#{Gitlab::BackgroundMigration::UserMentions::Models}::#{resource_class_name}".constantize - - expect do - subject.perform(resource_class_name, join, conditions, false, resource_class.minimum(:id), resource_class.maximum(:id)) - end.to change { user_mentions.count }.by(1) - - user_mention = user_mentions.last - expect(user_mention.mentioned_users_ids.sort).to eq(mentioned_users.pluck(:id).sort) - expect(user_mention.mentioned_groups_ids.sort).to eq([group.id]) - expect(user_mention.mentioned_groups_ids.sort).not_to include(inaccessible_group.id) - - # check that performing the same job twice does not fail and does not change counts - expect do - subject.perform(resource_class_name, join, conditions, false, resource_class.minimum(:id), resource_class.maximum(:id)) - end.to change { user_mentions.count }.by(0) - end -end - -RSpec.shared_examples 'resource notes mentions migration' do |migration_class, resource_class_name| - it 'migrates mentions from note' do - join = migration_class::JOIN - conditions = migration_class::QUERY_CONDITIONS - - # there are 5 notes for each noteable_type, but two do not have mentions and - # another one's noteable_id points to an inexistent resource - expect(notes.where(noteable_type: resource_class_name).count).to eq 5 - expect(user_mentions.count).to eq 0 - - expect do - subject.perform(resource_class_name, join, conditions, true, Note.minimum(:id), Note.maximum(:id)) - end.to change { user_mentions.count }.by(2) - - # check that the user_mention for regular note is created - user_mention = user_mentions.first - expect(Note.find(user_mention.note_id).system).to be false - expect(user_mention.mentioned_users_ids.sort).to eq(users.pluck(:id).sort) - expect(user_mention.mentioned_groups_ids.sort).to eq([group.id]) - expect(user_mention.mentioned_groups_ids.sort).not_to include(inaccessible_group.id) - - # check that the user_mention for system note is created - user_mention = user_mentions.second - expect(Note.find(user_mention.note_id).system).to be true - expect(user_mention.mentioned_users_ids.sort).to eq(users.pluck(:id).sort) - expect(user_mention.mentioned_groups_ids.sort).to eq([group.id]) - expect(user_mention.mentioned_groups_ids.sort).not_to include(inaccessible_group.id) - - # check that performing the same job twice does not fail and does not change counts - expect do - subject.perform(resource_class_name, join, conditions, true, Note.minimum(:id), Note.maximum(:id)) - end.to change { user_mentions.count }.by(0) - end -end - -RSpec.shared_examples 'schedules resource mentions migration' do |resource_class, is_for_notes| - before do - stub_const("#{described_class.name}::BATCH_SIZE", 1) - end - - it 'schedules background migrations' do - Sidekiq::Testing.fake! do - freeze_time do - resource_count = is_for_notes ? Note.count : resource_class.count - expect(resource_count).to eq 5 - - migrate! - - migration = described_class::MIGRATION - join = described_class::JOIN - conditions = described_class::QUERY_CONDITIONS - delay = described_class::DELAY - - expect(migration).to be_scheduled_delayed_migration(1 * delay, resource_class.name, join, conditions, is_for_notes, resource1.id, resource1.id) - expect(migration).to be_scheduled_delayed_migration(2 * delay, resource_class.name, join, conditions, is_for_notes, resource2.id, resource2.id) - expect(migration).to be_scheduled_delayed_migration(3 * delay, resource_class.name, join, conditions, is_for_notes, resource3.id, resource3.id) - expect(BackgroundMigrationWorker.jobs.size).to eq 3 - end - end - end -end - -RSpec.shared_examples 'resource migration not run' do |migration_class, resource_class_name| - it 'does not migrate mentions' do - join = migration_class::JOIN - conditions = migration_class::QUERY_CONDITIONS - resource_class = "#{Gitlab::BackgroundMigration::UserMentions::Models}::#{resource_class_name}".constantize - - expect do - subject.perform(resource_class_name, join, conditions, false, resource_class.minimum(:id), resource_class.maximum(:id)) - end.to change { user_mentions.count }.by(0) - end -end - -RSpec.shared_examples 'resource notes migration not run' do |migration_class, resource_class_name| - it 'does not migrate mentions' do - join = migration_class::JOIN - conditions = migration_class::QUERY_CONDITIONS - - expect do - subject.perform(resource_class_name, join, conditions, true, Note.minimum(:id), Note.maximum(:id)) - end.to change { user_mentions.count }.by(0) - 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 bd8bdd70ce5..bce889b454d 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 @@ -9,7 +9,7 @@ RSpec.shared_examples_for 'value stream 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).to respond_to(:markdown_description) } + it { expect(instance).to respond_to(:html_description) } it { expect(instance.column_list).to be_a_kind_of(Array) } describe '#apply_query_customization' do diff --git a/spec/support/shared_examples/lib/gitlab/import_export/attributes_permitter_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/import_export/attributes_permitter_shared_examples.rb index 41d3d76b66b..03344584361 100644 --- a/spec/support/shared_examples/lib/gitlab/import_export/attributes_permitter_shared_examples.rb +++ b/spec/support/shared_examples/lib/gitlab/import_export/attributes_permitter_shared_examples.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true RSpec.shared_examples 'a permitted attribute' do |relation_sym, permitted_attributes, additional_attributes = []| - let(:prohibited_attributes) { %i[remote_url my_attributes my_ids token my_id test] } + let(:prohibited_attributes) { %w[remote_url my_attributes my_ids token my_id test] } let(:import_export_config) { Gitlab::ImportExport::Config.new.to_h } let(:project_relation_factory) { Gitlab::ImportExport::Project::RelationFactory } @@ -8,7 +8,7 @@ RSpec.shared_examples 'a permitted attribute' do |relation_sym, permitted_attrib let(:relation_hash) { (permitted_attributes + prohibited_attributes).map(&:to_s).zip([]).to_h } let(:relation_name) { project_relation_factory.overrides[relation_sym]&.to_sym || relation_sym } let(:relation_class) { project_relation_factory.relation_class(relation_name) } - let(:excluded_keys) { import_export_config.dig(:excluded_keys, relation_sym) || [] } + let(:excluded_keys) { (import_export_config.dig(:excluded_attributes, relation_sym) || []).map(&:to_s) } let(:cleaned_hash) do Gitlab::ImportExport::AttributeCleaner.new( @@ -18,7 +18,7 @@ RSpec.shared_examples 'a permitted attribute' do |relation_sym, permitted_attrib ).clean end - let(:permitted_hash) { subject.permit(relation_sym, relation_hash) } + let(:permitted_hash) { subject.permit(relation_sym, relation_hash).transform_keys { |k| k.to_s } } if described_class.new.permitted_attributes_defined?(relation_sym) it 'contains only attributes that are defined as permitted in the import/export config' do @@ -26,11 +26,11 @@ RSpec.shared_examples 'a permitted attribute' do |relation_sym, permitted_attrib end it 'does not contain attributes that would be cleaned with AttributeCleaner' do - expect(cleaned_hash.keys + additional_attributes.to_a).to include(*permitted_hash.keys) + expect(cleaned_hash.keys + additional_attributes.to_a.map(&:to_s)).to include(*permitted_hash.keys) end it 'does not contain prohibited attributes that are not related to given relation' do - expect(permitted_hash.keys).not_to include(*prohibited_attributes.map(&:to_s)) + expect(permitted_hash.keys).not_to include(*prohibited_attributes) end else it 'is disabled' do diff --git a/spec/support/shared_examples/lib/gitlab/redis/multi_store_feature_flags_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/redis/multi_store_feature_flags_shared_examples.rb new file mode 100644 index 00000000000..046c70bf779 --- /dev/null +++ b/spec/support/shared_examples/lib/gitlab/redis/multi_store_feature_flags_shared_examples.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'multi store feature flags' do |use_primary_and_secondary_stores, use_primary_store_as_default| + context "with feature flag :#{use_primary_and_secondary_stores} is enabled" do + before do + stub_feature_flags(use_primary_and_secondary_stores => true) + end + + it 'multi store is enabled' do + expect(subject.use_primary_and_secondary_stores?).to be true + end + end + + context "with feature flag :#{use_primary_and_secondary_stores} is disabled" do + before do + stub_feature_flags(use_primary_and_secondary_stores => false) + end + + it 'multi store is disabled' do + expect(subject.use_primary_and_secondary_stores?).to be false + end + end + + context "with feature flag :#{use_primary_store_as_default} is enabled" do + before do + stub_feature_flags(use_primary_store_as_default => true) + end + + it 'primary store is enabled' do + expect(subject.use_primary_store_as_default?).to be true + end + end + + context "with feature flag :#{use_primary_store_as_default} is disabled" do + before do + stub_feature_flags(use_primary_store_as_default => false) + end + + it 'primary store is disabled' do + expect(subject.use_primary_store_as_default?).to be false + end + end +end |