diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 07:08:36 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 07:08:36 +0000 |
commit | 48aff82709769b098321c738f3444b9bdaa694c6 (patch) | |
tree | e00c7c43e2d9b603a5a6af576b1685e400410dee /spec/support/shared_examples/lib | |
parent | 879f5329ee916a948223f8f43d77fba4da6cd028 (diff) | |
download | gitlab-ce-48aff82709769b098321c738f3444b9bdaa694c6.tar.gz |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'spec/support/shared_examples/lib')
-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/ci/ci_trace_shared_examples.rb | 6 | ||||
-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/repository_size_checker_shared_examples.rb | 51 | ||||
-rw-r--r-- | spec/support/shared_examples/lib/gitlab/search/recent_items.rb | 43 | ||||
-rw-r--r-- | spec/support/shared_examples/lib/gitlab/search_confidential_filter_shared_examples.rb | 69 | ||||
-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 |
9 files changed, 290 insertions, 31 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/ci/ci_trace_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/ci/ci_trace_shared_examples.rb index db5e9461f3f..0df1af3b10a 100644 --- a/spec/support/shared_examples/lib/gitlab/ci/ci_trace_shared_examples.rb +++ b/spec/support/shared_examples/lib/gitlab/ci/ci_trace_shared_examples.rb @@ -227,7 +227,7 @@ RSpec.shared_examples 'common trace features' do let(:token) { 'my_secret_token' } before do - build.project.update(runners_token: token) + build.project.update!(runners_token: token) trace.append(token, 0) end @@ -240,7 +240,7 @@ RSpec.shared_examples 'common trace features' do let(:token) { 'my_secret_token' } before do - build.update(token: token) + build.update!(token: token) trace.append(token, 0) end @@ -531,7 +531,7 @@ RSpec.shared_examples 'trace with disabled live trace feature' do context "when erase old trace with 'save'" do before do build.send(:write_attribute, :trace, nil) - build.save + build.save # rubocop:disable Rails/SaveBang end it 'old trace is not deleted' 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 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/repository_size_checker_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/repository_size_checker_shared_examples.rb new file mode 100644 index 00000000000..bb909ffe82a --- /dev/null +++ b/spec/support/shared_examples/lib/gitlab/repository_size_checker_shared_examples.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'checker size above limit' do + context 'when size is above the limit' do + let(:current_size) { 100 } + + it 'returns true' do + expect(subject.above_size_limit?).to eq(true) + end + end +end + +RSpec.shared_examples 'checker size not over limit' do + it 'returns false when not over the limit' do + expect(subject.above_size_limit?).to eq(false) + end +end + +RSpec.shared_examples 'checker size exceeded' do + context 'when current size is below or equal to the limit' do + let(:current_size) { 50 } + + it 'returns zero' do + expect(subject.exceeded_size).to eq(0) + end + end + + context 'when current size is over the limit' do + let(:current_size) { 51 } + + it 'returns zero' do + expect(subject.exceeded_size).to eq(1.megabytes) + end + end + + context 'when change size will be over the limit' do + let(:current_size) { 50 } + + it 'returns zero' do + expect(subject.exceeded_size(1.megabytes)).to eq(1.megabytes) + end + end + + context 'when change size will not be over the limit' do + let(:current_size) { 49 } + + it 'returns zero' do + expect(subject.exceeded_size(1.megabytes)).to eq(0) + end + end +end diff --git a/spec/support/shared_examples/lib/gitlab/search/recent_items.rb b/spec/support/shared_examples/lib/gitlab/search/recent_items.rb index f96ff4b101e..b3b33e434b9 100644 --- a/spec/support/shared_examples/lib/gitlab/search/recent_items.rb +++ b/spec/support/shared_examples/lib/gitlab/search/recent_items.rb @@ -1,12 +1,11 @@ # frozen_string_literal: true require 'spec_helper' - RSpec.shared_examples 'search recent items' do let_it_be(:user) { create(:user) } - let_it_be(:recent_items) { described_class.new(user: user, items_limit: 5) } - let(:item) { create_item(content: 'hello world 1', project: project) } - let(:project) { create(:project, :public) } + let_it_be(:recent_items) { described_class.new(user: user) } + let(:item) { create_item(content: 'hello world 1', parent: parent) } + let(:parent) { create(parent_type, :public) } describe '#log_view', :clean_gitlab_redis_shared_state do it 'adds the item to the recent items' do @@ -18,13 +17,15 @@ RSpec.shared_examples 'search recent items' do end it 'removes an item when it exceeds the size items_limit' do - (1..6).each do |i| - recent_items.log_view(create_item(content: "item #{i}", project: project)) + recent_items = described_class.new(user: user, items_limit: 3) + + 4.times do |i| + recent_items.log_view(create_item(content: "item #{i}", parent: parent)) end results = recent_items.search('item') - expect(results.map(&:title)).to contain_exactly('item 6', 'item 5', 'item 4', 'item 3', 'item 2') + expect(results.map(&:title)).to contain_exactly('item 3', 'item 2', 'item 1') end it 'expires the items after expires_after' do @@ -39,7 +40,7 @@ RSpec.shared_examples 'search recent items' do it 'does not include results logged for another user' do another_user = create(:user) - another_item = create_item(content: 'hello world 2', project: project) + another_item = create_item(content: 'hello world 2', parent: parent) described_class.new(user: another_user).log_view(another_item) recent_items.log_view(item) @@ -50,11 +51,11 @@ RSpec.shared_examples 'search recent items' do end describe '#search', :clean_gitlab_redis_shared_state do - let(:item1) { create_item(content: "matching item 1", project: project) } - let(:item2) { create_item(content: "matching item 2", project: project) } - let(:item3) { create_item(content: "matching item 3", project: project) } - let(:non_matching_item) { create_item(content: "different item", project: project) } - let!(:non_viewed_item) { create_item(content: "matching but not viewed item", project: project) } + let(:item1) { create_item(content: "matching item 1", parent: parent) } + let(:item2) { create_item(content: "matching item 2", parent: parent) } + let(:item3) { create_item(content: "matching item 3", parent: parent) } + let(:non_matching_item) { create_item(content: "different item", parent: parent) } + let!(:non_viewed_item) { create_item(content: "matching but not viewed item", parent: parent) } before do recent_items.log_view(item1) @@ -74,14 +75,24 @@ RSpec.shared_examples 'search recent items' do end it 'does not leak items you no longer have access to' do - private_project = create(:project, :public, namespace: create(:group)) - private_item = create_item(content: 'matching item title', project: private_project) + private_parent = create(parent_type, :public) + private_item = create_item(content: 'matching item title', parent: private_parent) recent_items.log_view(private_item) - private_project.update!(visibility_level: Project::PRIVATE) + private_parent.update!(visibility_level: ::Gitlab::VisibilityLevel::PRIVATE) expect(recent_items.search('matching')).not_to include(private_item) end + + it "limits results to #{Gitlab::Search::RecentItems::SEARCH_LIMIT} items" do + (Gitlab::Search::RecentItems::SEARCH_LIMIT + 1).times do |i| + recent_items.log_view(create_item(content: "item #{i}", parent: parent)) + end + + results = recent_items.search('item') + + expect(results.count).to eq(Gitlab::Search::RecentItems::SEARCH_LIMIT) + 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..d0bef2ad730 --- /dev/null +++ b/spec/support/shared_examples/lib/gitlab/search_confidential_filter_shared_examples.rb @@ -0,0 +1,69 @@ +# 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: true } } + + 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: false } } + + 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 +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 |