diff options
Diffstat (limited to 'spec/support/shared_examples/lib/gitlab')
-rw-r--r-- | spec/support/shared_examples/lib/gitlab/background_migration/mentions_migration_shared_examples.rb | 24 | ||||
-rw-r--r-- | spec/support/shared_examples/lib/gitlab/diff_file_collections_shared_examples.rb | 2 | ||||
-rw-r--r-- | spec/support/shared_examples/lib/gitlab/import_export/relation_factory_shared_examples.rb | 107 | ||||
-rw-r--r-- | spec/support/shared_examples/lib/gitlab/search_confidential_filter_shared_examples.rb | 91 | ||||
-rw-r--r-- | spec/support/shared_examples/lib/gitlab/search_results_sorted_shared_examples.rb | 19 | ||||
-rw-r--r-- | spec/support/shared_examples/lib/gitlab/search_state_filter_shared_examples.rb (renamed from spec/support/shared_examples/lib/gitlab/search_issue_state_filter_shared_examples.rb) | 0 |
6 files changed, 231 insertions, 12 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 e93077c42e1..7707e79386c 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,12 +1,13 @@ # frozen_string_literal: true -RSpec.shared_examples 'resource mentions migration' do |migration_class, resource_class| +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)) + 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 @@ -16,23 +17,23 @@ RSpec.shared_examples 'resource mentions migration' do |migration_class, resourc # 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)) + 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| +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.to_s).count).to eq 5 + 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)) + 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 @@ -51,7 +52,7 @@ RSpec.shared_examples 'resource notes mentions migration' do |migration_class, r # 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)) + subject.perform(resource_class_name, join, conditions, true, Note.minimum(:id), Note.maximum(:id)) end.to change { user_mentions.count }.by(0) end end @@ -83,24 +84,25 @@ RSpec.shared_examples 'schedules resource mentions migration' do |resource_class end end -RSpec.shared_examples 'resource migration not run' do |migration_class, resource_class| +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)) + 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| +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)) + 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/diff_file_collections_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/diff_file_collections_shared_examples.rb index e43ce936b90..469c0c287b1 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 @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.shared_examples 'diff statistics' do |test_include_stats_flag: true| - subject { described_class.new(diffable, collection_default_args) } + subject { described_class.new(diffable, **collection_default_args) } def stub_stats_find_by_path(path, stats_mock) expect_next_instance_of(Gitlab::Git::DiffStatsCollection) do |collection| diff --git a/spec/support/shared_examples/lib/gitlab/import_export/relation_factory_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/import_export/relation_factory_shared_examples.rb new file mode 100644 index 00000000000..33061f17bde --- /dev/null +++ b/spec/support/shared_examples/lib/gitlab/import_export/relation_factory_shared_examples.rb @@ -0,0 +1,107 @@ +# frozen_string_literal: true + +# required context: +# - importable: group or project +# - relation_hash: a note relation that's being imported +# - created_object: the object created with the relation factory +RSpec.shared_examples 'Notes user references' do + let(:relation_sym) { :notes } + let(:mapped_user) { create(:user) } + let(:exported_member) do + { + 'id' => 111, + 'access_level' => 30, + 'source_id' => 1, + 'source_type' => importable.class.name == 'Project' ? 'Project' : 'Namespace', + 'user_id' => 3, + 'notification_level' => 3, + 'created_at' => '2016-11-18T09:29:42.634Z', + 'updated_at' => '2016-11-18T09:29:42.634Z', + 'user' => { + 'id' => 999, + 'email' => mapped_user.email, + 'username' => mapped_user.username + } + } + end + + let(:members_mapper) do + Gitlab::ImportExport::MembersMapper.new( + exported_members: [exported_member].compact, + user: importer_user, + importable: importable + ) + end + + shared_examples 'sets the note author to the importer user' do + it { expect(created_object.author).to eq(importer_user) } + end + + shared_examples 'sets the note author to the mapped user' do + it { expect(created_object.author).to eq(mapped_user) } + end + + shared_examples 'does not add original autor note' do + it { expect(created_object.note).not_to include('*By Administrator') } + end + + shared_examples 'adds original autor note' do + it { expect(created_object.note).to include('*By Administrator') } + end + + context 'when the importer is admin' do + let(:importer_user) { create(:admin) } + + context 'and the note author is not mapped' do + let(:exported_member) { nil } + + include_examples 'sets the note author to the importer user' + + include_examples 'adds original autor note' + end + + context 'and the note author is the importer user' do + let(:mapped_user) { importer_user } + + include_examples 'sets the note author to the mapped user' + + include_examples 'does not add original autor note' + end + + context 'and the note author exists in the target instance' do + let(:mapped_user) { create(:user) } + + include_examples 'sets the note author to the mapped user' + + include_examples 'does not add original autor note' + end + end + + context 'when the importer is not admin' do + let(:importer_user) { create(:user) } + + context 'and the note author is not mapped' do + let(:exported_member) { nil } + + include_examples 'sets the note author to the importer user' + + include_examples 'adds original autor note' + end + + context 'and the note author is the importer user' do + let(:mapped_user) { importer_user } + + include_examples 'sets the note author to the importer user' + + include_examples 'adds original autor note' + end + + context 'and the note author exists in the target instance' do + let(:mapped_user) { create(:user) } + + include_examples 'sets the note author to the importer user' + + include_examples 'adds original autor note' + end + end +end diff --git a/spec/support/shared_examples/lib/gitlab/search_confidential_filter_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/search_confidential_filter_shared_examples.rb new file mode 100644 index 00000000000..6c8ab38413d --- /dev/null +++ b/spec/support/shared_examples/lib/gitlab/search_confidential_filter_shared_examples.rb @@ -0,0 +1,91 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'search results filtered by confidential' do + context 'filter not provided (all behavior)' do + let(:filters) { {} } + + context 'when Feature search_filter_by_confidential enabled' do + it 'returns confidential and not confidential results', :aggregate_failures do + expect(results.objects('issues')).to include confidential_result + expect(results.objects('issues')).to include opened_result + end + end + + context 'when Feature search_filter_by_confidential not enabled' do + before do + stub_feature_flags(search_filter_by_confidential: false) + end + + it 'returns confidential and not confidential results', :aggregate_failures do + expect(results.objects('issues')).to include confidential_result + expect(results.objects('issues')).to include opened_result + end + end + end + + context 'confidential filter' do + let(:filters) { { confidential: 'yes' } } + + context 'when Feature search_filter_by_confidential enabled' do + it 'returns only confidential results', :aggregate_failures do + expect(results.objects('issues')).to include confidential_result + expect(results.objects('issues')).not_to include opened_result + end + end + + context 'when Feature search_filter_by_confidential not enabled' do + before do + stub_feature_flags(search_filter_by_confidential: false) + end + + it 'returns confidential and not confidential results', :aggregate_failures do + expect(results.objects('issues')).to include confidential_result + expect(results.objects('issues')).to include opened_result + end + end + end + + context 'not confidential filter' do + let(:filters) { { confidential: 'no' } } + + context 'when Feature search_filter_by_confidential enabled' do + it 'returns not confidential results', :aggregate_failures do + expect(results.objects('issues')).not_to include confidential_result + expect(results.objects('issues')).to include opened_result + end + end + + context 'when Feature search_filter_by_confidential not enabled' do + before do + stub_feature_flags(search_filter_by_confidential: false) + end + + it 'returns confidential and not confidential results', :aggregate_failures do + expect(results.objects('issues')).to include confidential_result + expect(results.objects('issues')).to include opened_result + end + end + end + + context 'unsupported filter' do + let(:filters) { { confidential: 'goodbye' } } + + context 'when Feature search_filter_by_confidential enabled' do + it 'returns confidential and not confidential results', :aggregate_failures do + expect(results.objects('issues')).to include confidential_result + expect(results.objects('issues')).to include opened_result + end + end + + context 'when Feature search_filter_by_confidential not enabled' do + before do + stub_feature_flags(search_filter_by_confidential: false) + end + + it 'returns confidential and not confidential results', :aggregate_failures do + expect(results.objects('issues')).to include confidential_result + expect(results.objects('issues')).to include opened_result + end + end + end +end diff --git a/spec/support/shared_examples/lib/gitlab/search_results_sorted_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/search_results_sorted_shared_examples.rb new file mode 100644 index 00000000000..765279a78fe --- /dev/null +++ b/spec/support/shared_examples/lib/gitlab/search_results_sorted_shared_examples.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'search results sorted' do + context 'sort: newest' do + let(:sort) { 'newest' } + + it 'sorts results by created_at' do + expect(results.objects(scope).map(&:id)).to eq([new_result.id, old_result.id, very_old_result.id]) + end + end + + context 'sort: oldest' do + let(:sort) { 'oldest' } + + it 'sorts results by created_at' do + expect(results.objects(scope).map(&:id)).to eq([very_old_result.id, old_result.id, new_result.id]) + end + end +end diff --git a/spec/support/shared_examples/lib/gitlab/search_issue_state_filter_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/search_state_filter_shared_examples.rb index e80ec516407..e80ec516407 100644 --- a/spec/support/shared_examples/lib/gitlab/search_issue_state_filter_shared_examples.rb +++ b/spec/support/shared_examples/lib/gitlab/search_state_filter_shared_examples.rb |