diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-19 15:57:54 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-19 15:57:54 +0300 |
commit | 419c53ec62de6e97a517abd5fdd4cbde3a942a34 (patch) | |
tree | 1f43a548b46bca8a5fb8fe0c31cef1883d49c5b6 /spec/finders | |
parent | 1da20d9135b3ad9e75e65b028bffc921aaf8deb7 (diff) |
Add latest changes from gitlab-org/gitlab@16-5-stable-eev16.5.0-rc42
Diffstat (limited to 'spec/finders')
-rw-r--r-- | spec/finders/alert_management/alerts_finder_spec.rb | 4 | ||||
-rw-r--r-- | spec/finders/branches_finder_spec.rb | 14 | ||||
-rw-r--r-- | spec/finders/ci/runners_finder_spec.rb | 2 | ||||
-rw-r--r-- | spec/finders/concerns/packages/finder_helper_spec.rb | 30 | ||||
-rw-r--r-- | spec/finders/environments/environments_finder_spec.rb | 4 | ||||
-rw-r--r-- | spec/finders/groups_finder_spec.rb | 48 | ||||
-rw-r--r-- | spec/finders/license_template_finder_spec.rb | 2 | ||||
-rw-r--r-- | spec/finders/merge_requests/oldest_per_commit_finder_spec.rb | 35 | ||||
-rw-r--r-- | spec/finders/merge_requests_finder_spec.rb | 6 | ||||
-rw-r--r-- | spec/finders/packages/maven/package_finder_spec.rb | 22 | ||||
-rw-r--r-- | spec/finders/packages/npm/packages_for_user_finder_spec.rb | 18 | ||||
-rw-r--r-- | spec/finders/projects/ml/model_finder_spec.rb | 4 | ||||
-rw-r--r-- | spec/finders/snippets_finder_spec.rb | 48 | ||||
-rw-r--r-- | spec/finders/tags_finder_spec.rb | 12 | ||||
-rw-r--r-- | spec/finders/template_finder_spec.rb | 4 | ||||
-rw-r--r-- | spec/finders/vs_code/settings/settings_finder_spec.rb | 64 |
16 files changed, 250 insertions, 67 deletions
diff --git a/spec/finders/alert_management/alerts_finder_spec.rb b/spec/finders/alert_management/alerts_finder_spec.rb index 3c37d52d6c3..4d0324b9f1a 100644 --- a/spec/finders/alert_management/alerts_finder_spec.rb +++ b/spec/finders/alert_management/alerts_finder_spec.rb @@ -183,7 +183,7 @@ RSpec.describe AlertManagement::AlertsFinder, '#execute' do let(:params) { { sort: 'severity_asc' } } it 'sorts alerts by severity from less critical to more critical' do - expect(execute.pluck(:severity).uniq).to eq(%w(unknown info low medium high critical)) + expect(execute.pluck(:severity).uniq).to eq(%w[unknown info low medium high critical]) end end @@ -191,7 +191,7 @@ RSpec.describe AlertManagement::AlertsFinder, '#execute' do let(:params) { { sort: 'severity_desc' } } it 'sorts alerts by severity from more critical to less critical' do - expect(execute.pluck(:severity).uniq).to eq(%w(critical high medium low info unknown)) + expect(execute.pluck(:severity).uniq).to eq(%w[critical high medium low info unknown]) end end end diff --git a/spec/finders/branches_finder_spec.rb b/spec/finders/branches_finder_spec.rb index 9f185c8b8fb..004629eda95 100644 --- a/spec/finders/branches_finder_spec.rb +++ b/spec/finders/branches_finder_spec.rb @@ -92,7 +92,7 @@ RSpec.describe BranchesFinder, feature_category: :source_code_management do result = subject expect(result.count).to eq(3) - expect(result.map(&:name)).to eq(%w{csv fix lfs}) + expect(result.map(&:name)).to eq(%w[csv fix lfs]) end end @@ -265,7 +265,7 @@ RSpec.describe BranchesFinder, feature_category: :source_code_management do it 'filters branches' do result = subject - expect(result.map(&:name)).to eq(%w(feature_conflict few-commits)) + expect(result.map(&:name)).to eq(%w[feature_conflict few-commits]) end end @@ -275,7 +275,7 @@ RSpec.describe BranchesFinder, feature_category: :source_code_management do it 'filters branches' do result = subject - expect(result.map(&:name)).to eq(%w(fix flatten-dir)) + expect(result.map(&:name)).to eq(%w[fix flatten-dir]) end end @@ -306,7 +306,7 @@ RSpec.describe BranchesFinder, feature_category: :source_code_management do it 'filters branches' do result = subject - expect(result.map(&:name)).to eq(%w(feature improve/awesome merge-test markdown feature_conflict)) + expect(result.map(&:name)).to eq(%w[feature improve/awesome merge-test markdown feature_conflict]) end end @@ -316,7 +316,7 @@ RSpec.describe BranchesFinder, feature_category: :source_code_management do it 'filters branches' do result = subject - expect(result.map(&:name)).to eq(%w(merge-test markdown)) + expect(result.map(&:name)).to eq(%w[merge-test markdown]) end end end @@ -328,7 +328,7 @@ RSpec.describe BranchesFinder, feature_category: :source_code_management do result = subject expect(result.count).to eq(3) - expect(result.map(&:name)).to eq(%w{csv fix lfs}) + expect(result.map(&:name)).to eq(%w[csv fix lfs]) end end @@ -338,7 +338,7 @@ RSpec.describe BranchesFinder, feature_category: :source_code_management do it 'falls back to default execute and ignore paginations' do result = subject - expect(result.map(&:name)).to eq(%w(feature feature_conflict few-commits fix flatten-dir)) + expect(result.map(&:name)).to eq(%w[feature feature_conflict few-commits fix flatten-dir]) end end end diff --git a/spec/finders/ci/runners_finder_spec.rb b/spec/finders/ci/runners_finder_spec.rb index 5d249ddb391..06cca035c6f 100644 --- a/spec/finders/ci/runners_finder_spec.rb +++ b/spec/finders/ci/runners_finder_spec.rb @@ -171,7 +171,7 @@ RSpec.describe Ci::RunnersFinder, feature_category: :runner_fleet do it_behaves_like 'sorts by created_at descending' end - %w(created_date created_at_desc).each do |sort| + %w[created_date created_at_desc].each do |sort| context "with sort param equal to #{sort}" do let(:params) { { sort: sort } } diff --git a/spec/finders/concerns/packages/finder_helper_spec.rb b/spec/finders/concerns/packages/finder_helper_spec.rb index 94bcec6163e..f81e940c7ed 100644 --- a/spec/finders/concerns/packages/finder_helper_spec.rb +++ b/spec/finders/concerns/packages/finder_helper_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ::Packages::FinderHelper do +RSpec.describe ::Packages::FinderHelper, feature_category: :package_registry do describe '#packages_for_project' do let_it_be_with_reload(:project1) { create(:project) } let_it_be(:package1) { create(:package, project: project1) } @@ -107,6 +107,34 @@ RSpec.describe ::Packages::FinderHelper do it_behaves_like params[:shared_example_name] end + + context 'when the second project has the package registry disabled' do + before do + project1.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC) + project2.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC, + package_registry_access_level: 'disabled', packages_enabled: false) + end + + it_behaves_like 'returning both packages' + + context 'with with_package_registry_enabled set to true' do + let(:finder_class) do + Class.new do + include ::Packages::FinderHelper + + def initialize(user) + @current_user = user + end + + def execute(group) + packages_visible_to_user(@current_user, within_group: group, with_package_registry_enabled: true) + end + end + end + + it_behaves_like 'returning package1' + end + end end context 'with a group deploy token' do diff --git a/spec/finders/environments/environments_finder_spec.rb b/spec/finders/environments/environments_finder_spec.rb index df66bbdc235..e3b1a121497 100644 --- a/spec/finders/environments/environments_finder_spec.rb +++ b/spec/finders/environments/environments_finder_spec.rb @@ -24,13 +24,13 @@ RSpec.describe Environments::EnvironmentsFinder do end it 'returns environments with any of the requested states' do - result = described_class.new(project, user, states: %w(available stopped)).execute + result = described_class.new(project, user, states: %w[available stopped]).execute expect(result).to contain_exactly(environment, environment_stopped, environment_available, stopped_environment) end it 'raises exception when requested state is invalid' do - expect { described_class.new(project, user, states: %w(invalid stopped)).execute }.to( + expect { described_class.new(project, user, states: %w[invalid stopped]).execute }.to( raise_error(described_class::InvalidStatesError, 'Requested states are invalid') ) end diff --git a/spec/finders/groups_finder_spec.rb b/spec/finders/groups_finder_spec.rb index 23d73b48199..f20c03c9658 100644 --- a/spec/finders/groups_finder_spec.rb +++ b/spec/finders/groups_finder_spec.rb @@ -12,30 +12,30 @@ RSpec.describe GroupsFinder, feature_category: :groups_and_projects do using RSpec::Parameterized::TableSyntax where(:user_type, :params, :results) do - nil | { all_available: true } | %i(public_group user_public_group) - nil | { all_available: false } | %i(public_group user_public_group) - nil | {} | %i(public_group user_public_group) - - :regular | { all_available: true } | %i(public_group internal_group user_public_group user_internal_group - user_private_group) - :regular | { all_available: false } | %i(user_public_group user_internal_group user_private_group) - :regular | {} | %i(public_group internal_group user_public_group user_internal_group user_private_group) - :regular | { min_access_level: Gitlab::Access::DEVELOPER } | %i(user_public_group user_internal_group user_private_group) - - :external | { all_available: true } | %i(public_group user_public_group user_internal_group user_private_group) - :external | { all_available: false } | %i(user_public_group user_internal_group user_private_group) - :external | {} | %i(public_group user_public_group user_internal_group user_private_group) - - :admin_without_admin_mode | { all_available: true } | %i(public_group internal_group user_public_group - user_internal_group user_private_group) - :admin_without_admin_mode | { all_available: false } | %i(user_public_group user_internal_group user_private_group) - :admin_without_admin_mode | {} | %i(public_group internal_group user_public_group user_internal_group user_private_group) - - :admin_with_admin_mode | { all_available: true } | %i(public_group internal_group private_group user_public_group - user_internal_group user_private_group) - :admin_with_admin_mode | { all_available: false } | %i(user_public_group user_internal_group user_private_group) - :admin_with_admin_mode | {} | %i(public_group internal_group private_group user_public_group user_internal_group - user_private_group) + nil | { all_available: true } | %i[public_group user_public_group] + nil | { all_available: false } | %i[public_group user_public_group] + nil | {} | %i[public_group user_public_group] + + :regular | { all_available: true } | %i[public_group internal_group user_public_group user_internal_group + user_private_group] + :regular | { all_available: false } | %i[user_public_group user_internal_group user_private_group] + :regular | {} | %i[public_group internal_group user_public_group user_internal_group user_private_group] + :regular | { min_access_level: Gitlab::Access::DEVELOPER } | %i[user_public_group user_internal_group user_private_group] + + :external | { all_available: true } | %i[public_group user_public_group user_internal_group user_private_group] + :external | { all_available: false } | %i[user_public_group user_internal_group user_private_group] + :external | {} | %i[public_group user_public_group user_internal_group user_private_group] + + :admin_without_admin_mode | { all_available: true } | %i[public_group internal_group user_public_group + user_internal_group user_private_group] + :admin_without_admin_mode | { all_available: false } | %i[user_public_group user_internal_group user_private_group] + :admin_without_admin_mode | {} | %i[public_group internal_group user_public_group user_internal_group user_private_group] + + :admin_with_admin_mode | { all_available: true } | %i[public_group internal_group private_group user_public_group + user_internal_group user_private_group] + :admin_with_admin_mode | { all_available: false } | %i[user_public_group user_internal_group user_private_group] + :admin_with_admin_mode | {} | %i[public_group internal_group private_group user_public_group user_internal_group + user_private_group] end with_them do diff --git a/spec/finders/license_template_finder_spec.rb b/spec/finders/license_template_finder_spec.rb index 754b92faccc..21c4cf74fd0 100644 --- a/spec/finders/license_template_finder_spec.rb +++ b/spec/finders/license_template_finder_spec.rb @@ -75,7 +75,7 @@ RSpec.describe LicenseTemplateFinder do context 'template names hash keys' do it 'has all the expected keys' do - expect(template_names.values.flatten.first.keys).to match_array(%i(id key name project_id)) + expect(template_names.values.flatten.first.keys).to match_array(%i[id key name project_id]) end end end diff --git a/spec/finders/merge_requests/oldest_per_commit_finder_spec.rb b/spec/finders/merge_requests/oldest_per_commit_finder_spec.rb index 6dffaff294d..9832c74c6b8 100644 --- a/spec/finders/merge_requests/oldest_per_commit_finder_spec.rb +++ b/spec/finders/merge_requests/oldest_per_commit_finder_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe MergeRequests::OldestPerCommitFinder do +RSpec.describe MergeRequests::OldestPerCommitFinder, feature_category: :code_review_workflow do describe '#execute' do it 'returns a Hash mapping commit SHAs to their oldest merge requests' do project = create(:project) @@ -18,8 +18,8 @@ RSpec.describe MergeRequests::OldestPerCommitFinder do merge_commit_sha: sha3 ) - mr1_diff = create(:merge_request_diff, merge_request: mr1) - mr2_diff = create(:merge_request_diff, merge_request: mr2) + mr1_diff = mr1.merge_request_diff + mr2_diff = mr2.merge_request_diff create(:merge_request_diff_commit, merge_request_diff: mr1_diff, sha: sha1) create(:merge_request_diff_commit, merge_request_diff: mr2_diff, sha: sha1) @@ -71,6 +71,7 @@ RSpec.describe MergeRequests::OldestPerCommitFinder do # This expectation is set so we're certain that the merge commit SHAs (if # a matching merge request is found) aren't also used for finding MRs # according to diffs. + # expect(MergeRequestDiffCommit) .not_to receive(:oldest_merge_request_id_per_commit) @@ -116,6 +117,27 @@ RSpec.describe MergeRequests::OldestPerCommitFinder do .to eq(sha1 => mr, sha2 => mr) end + it 'includes a merge request for fast-forward merged MR' do + project = create(:project) + sha = Digest::SHA1.hexdigest('foo') + # When there is only a merged_commit_sha, then it means the MR was + # fast-forward merged without a squash, but possibly including a rebase. + mr = create( + :merge_request, + :merged, + target_project: project, + merged_commit_sha: sha + ) + + commits = [double(:commit1, id: sha)] + + expect(MergeRequestDiffCommit) + .not_to receive(:oldest_merge_request_id_per_commit) + + expect(described_class.new(project).execute(commits)) + .to eq(sha => mr) + end + it 'includes the oldest merge request when a merge commit is present in a newer merge request' do project = create(:project) sha = Digest::SHA1.hexdigest('foo') @@ -126,9 +148,12 @@ RSpec.describe MergeRequests::OldestPerCommitFinder do ) mr2 = create(:merge_request, :merged, target_project: project) - mr_diff = create(:merge_request_diff, merge_request: mr2) - create(:merge_request_diff_commit, merge_request_diff: mr_diff, sha: sha) + create( + :merge_request_diff_commit, + merge_request_diff: mr2.merge_request_diff, + sha: sha + ) commits = [double(:commit, id: sha)] diff --git a/spec/finders/merge_requests_finder_spec.rb b/spec/finders/merge_requests_finder_spec.rb index 9aa98189f30..3f9c1baec82 100644 --- a/spec/finders/merge_requests_finder_spec.rb +++ b/spec/finders/merge_requests_finder_spec.rb @@ -163,9 +163,9 @@ RSpec.describe MergeRequestsFinder, feature_category: :code_review_workflow do it { is_expected.to eq([merge_request2]) } it 'queries merge_request_metrics.target_project_id table' do - expect(query.to_sql).to include(%{"merge_request_metrics"."target_project_id" = #{merge_request2.target_project_id}}) + expect(query.to_sql).to include(%("merge_request_metrics"."target_project_id" = #{merge_request2.target_project_id})) - expect(query.to_sql).not_to include(%{"merge_requests"."target_project_id"}) + expect(query.to_sql).not_to include(%("merge_requests"."target_project_id")) end end end @@ -537,7 +537,7 @@ RSpec.describe MergeRequestsFinder, feature_category: :code_review_workflow do context 'filtering by approved by username' do let(:params) { { approved_by_usernames: user2.username } } - where(:sort) { [nil] + %w(milestone merged_at merged_at_desc closed_at closed_at_desc) } + where(:sort) { [nil] + %w[milestone merged_at merged_at_desc closed_at closed_at_desc] } before do create(:approval, merge_request: merge_request3, user: user2) diff --git a/spec/finders/packages/maven/package_finder_spec.rb b/spec/finders/packages/maven/package_finder_spec.rb index 8b45dbdad51..f769471fcc7 100644 --- a/spec/finders/packages/maven/package_finder_spec.rb +++ b/spec/finders/packages/maven/package_finder_spec.rb @@ -17,21 +17,21 @@ RSpec.describe ::Packages::Maven::PackageFinder do group.add_developer(user) end - describe '#execute!' do - subject { finder.execute! } + describe '#execute' do + subject { finder.execute } shared_examples 'handling valid and invalid paths' do context 'with a valid path' do let(:param_path) { package.maven_metadatum.path } - it { is_expected.to eq(package) } + it { is_expected.to include(package) } end context 'with an invalid path' do let(:param_path) { 'com/example/my-app/1.0-SNAPSHOT' } - it 'raises an error' do - expect { subject }.to raise_error(ActiveRecord::RecordNotFound) + it 'returns an empty array' do + is_expected.to be_empty end end @@ -42,7 +42,9 @@ RSpec.describe ::Packages::Maven::PackageFinder do package.update_column(:status, :error) end - it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) } + it 'returns an empty array' do + is_expected.to be_empty + end end end @@ -59,8 +61,8 @@ RSpec.describe ::Packages::Maven::PackageFinder do end context 'across all projects' do - it 'raises an error' do - expect { subject }.to raise_error(ActiveRecord::RecordNotFound) + it 'returns an empty array' do + is_expected.to be_empty end end @@ -86,13 +88,13 @@ RSpec.describe ::Packages::Maven::PackageFinder do end context 'without order by package file' do - it { is_expected.to eq(package3) } + it { is_expected.to match_array([package1, package2, package3]) } end context 'with order by package file' do let(:param_order_by_package_file) { true } - it { is_expected.to eq(package2) } + it { expect(subject.last).to eq(package2) } end end end diff --git a/spec/finders/packages/npm/packages_for_user_finder_spec.rb b/spec/finders/packages/npm/packages_for_user_finder_spec.rb index e2dc21e1008..ffbb4f9e484 100644 --- a/spec/finders/packages/npm/packages_for_user_finder_spec.rb +++ b/spec/finders/packages/npm/packages_for_user_finder_spec.rb @@ -36,6 +36,24 @@ RSpec.describe ::Packages::Npm::PackagesForUserFinder, feature_category: :packag end it_behaves_like 'searches for packages' + + context 'when an user is a reporter of both projects' do + before_all do + project2.add_reporter(user) + end + + it { is_expected.to contain_exactly(package, package_with_diff_project) } + + context 'when the second project has the package registry disabled' do + before_all do + project.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC) + project2.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC, + package_registry_access_level: 'disabled', packages_enabled: false) + end + + it_behaves_like 'searches for packages' + end + end end end end diff --git a/spec/finders/projects/ml/model_finder_spec.rb b/spec/finders/projects/ml/model_finder_spec.rb index 48333ae49e5..1d869e1792d 100644 --- a/spec/finders/projects/ml/model_finder_spec.rb +++ b/spec/finders/projects/ml/model_finder_spec.rb @@ -22,4 +22,8 @@ RSpec.describe Projects::Ml::ModelFinder, feature_category: :mlops do it 'does not return models belonging to a different project' do is_expected.not_to include(model3) end + + it 'includes version count' do + expect(models[0].version_count).to be(models[0].versions.count) + end end diff --git a/spec/finders/snippets_finder_spec.rb b/spec/finders/snippets_finder_spec.rb index a5cd90b444e..716eee5c9ac 100644 --- a/spec/finders/snippets_finder_spec.rb +++ b/spec/finders/snippets_finder_spec.rb @@ -112,9 +112,7 @@ RSpec.describe SnippetsFinder do expect(snippets).to contain_exactly(private_personal_snippet, internal_personal_snippet, public_personal_snippet) end - it 'returns all snippets (everything) for an admin when all_available="true" passed in' do - allow(admin).to receive(:can_read_all_resources?).and_return(true) - + it 'returns all snippets (everything) for an admin when all_available="true" passed in', :enable_admin_mode do snippets = described_class.new(admin, author: user, all_available: true).execute expect(snippets).to contain_exactly( @@ -326,6 +324,50 @@ RSpec.describe SnippetsFinder do end end + context 'filtering for snippets authored by banned users', feature_category: :insider_threat do + let_it_be(:banned_user) { create(:user, :banned) } + + let_it_be(:banned_public_personal_snippet) { create(:personal_snippet, :public, author: banned_user) } + let_it_be(:banned_public_project_snippet) { create(:project_snippet, :public, project: project, author: banned_user) } + + it 'returns banned snippets for admins when in admin mode', :enable_admin_mode do + snippets = described_class.new( + admin, + ids: [banned_public_personal_snippet.id, banned_public_project_snippet.id] + ).execute + + expect(snippets).to contain_exactly( + banned_public_personal_snippet, banned_public_project_snippet + ) + end + + it 'does not return banned snippets for non-admin users' do + snippets = described_class.new( + user, + ids: [banned_public_personal_snippet.id, banned_public_project_snippet.id] + ).execute + + expect(snippets).to be_empty + end + + context 'when hide_snippets_of_banned_users feature flag is off' do + before do + stub_feature_flags(hide_snippets_of_banned_users: false) + end + + it 'returns banned snippets for non-admin users' do + snippets = described_class.new( + user, + ids: [banned_public_personal_snippet.id, banned_public_project_snippet.id] + ).execute + + expect(snippets).to contain_exactly( + banned_public_personal_snippet, banned_public_project_snippet + ) + end + end + end + context 'when the user cannot read cross project' do before do allow(Ability).to receive(:allowed?).and_call_original diff --git a/spec/finders/tags_finder_spec.rb b/spec/finders/tags_finder_spec.rb index 2af23c466fb..525c19ba137 100644 --- a/spec/finders/tags_finder_spec.rb +++ b/spec/finders/tags_finder_spec.rb @@ -133,7 +133,7 @@ RSpec.describe TagsFinder do it 'filters tags' do result = subject - expect(result.map(&:name)).to eq(%w(v1.1.0)) + expect(result.map(&:name)).to eq(%w[v1.1.0]) end end @@ -143,7 +143,7 @@ RSpec.describe TagsFinder do it 'filters branches' do result = subject - expect(result.map(&:name)).to eq(%w(v1.1.1)) + expect(result.map(&:name)).to eq(%w[v1.1.1]) end end @@ -153,7 +153,7 @@ RSpec.describe TagsFinder do it 'filters branches' do result = subject - expect(result.map(&:name)).to eq(%w(v1.0.0 v1.1.0)) + expect(result.map(&:name)).to eq(%w[v1.0.0 v1.1.0]) end end @@ -174,7 +174,7 @@ RSpec.describe TagsFinder do it 'filters branches' do result = subject - expect(result.map(&:name)).to eq(%w(v1.1.1 v1.1.0 v1.0.0)) + expect(result.map(&:name)).to eq(%w[v1.1.1 v1.1.0 v1.0.0]) end end @@ -184,7 +184,7 @@ RSpec.describe TagsFinder do it 'filters branches' do result = subject - expect(result.map(&:name)).to eq(%w(v1.1.0 v1.0.0)) + expect(result.map(&:name)).to eq(%w[v1.1.0 v1.0.0]) end end end @@ -195,7 +195,7 @@ RSpec.describe TagsFinder do it 'ignores the pagination for search' do result = subject - expect(result.map(&:name)).to eq(%w(v1.1.1)) + expect(result.map(&:name)).to eq(%w[v1.1.1]) end end end diff --git a/spec/finders/template_finder_spec.rb b/spec/finders/template_finder_spec.rb index eacce0bd996..57956b5aa95 100644 --- a/spec/finders/template_finder_spec.rb +++ b/spec/finders/template_finder_spec.rb @@ -189,7 +189,7 @@ RSpec.describe TemplateFinder do context 'template names hash keys' do it 'has all the expected keys' do - expect(result.first.to_h.keys).to match_array(%i(id key name project_id)) + expect(result.first.to_h.keys).to match_array(%i[id key name project_id]) end end end @@ -223,7 +223,7 @@ RSpec.describe TemplateFinder do context 'template names hash keys' do it 'has all the expected keys' do - expect(result.first.to_h.keys).to match_array(%i(id key name project_id)) + expect(result.first.to_h.keys).to match_array(%i[id key name project_id]) end end end diff --git a/spec/finders/vs_code/settings/settings_finder_spec.rb b/spec/finders/vs_code/settings/settings_finder_spec.rb new file mode 100644 index 00000000000..b7b4308bbbd --- /dev/null +++ b/spec/finders/vs_code/settings/settings_finder_spec.rb @@ -0,0 +1,64 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe VsCode::Settings::SettingsFinder, feature_category: :web_ide do + let_it_be(:user) { create(:user) } + + describe '#execute' do + context 'when nil is passed in as the list of settings' do + let(:finder) { described_class.new(user, nil) } + + subject { finder.execute } + + context 'when user has no settings' do + it 'returns an empty array' do + expect(subject).to eq([]) + end + end + + context 'when user has settings' do + before do + create(:vscode_setting, user: user) + end + + it 'returns an array of settings' do + expect(subject.length).to eq(1) + expect(subject[0].user_id).to eq(user.id) + expect(subject[0].setting_type).to eq('settings') + end + end + end + + context 'when a list of settings is passed, filters by the setting' do + let_it_be(:setting) { create(:vscode_setting, user: user) } + + context 'when user has no settings with that type' do + subject { finder.execute } + + it 'returns an empty array' do + finder = described_class.new(user, ['profile']) + expect(finder.execute).to eq([]) + end + end + + context 'when user does have settings with the type' do + subject { finder.execute } + + it 'returns the record when a single setting exists' do + result = described_class.new(user, ['settings']).execute + expect(result.length).to eq(1) + expect(result[0].user_id).to eq(user.id) + expect(result[0].setting_type).to eq('settings') + end + + it 'returns multiple records when more than one setting exists' do + create(:vscode_setting, user: user, setting_type: 'profile') + + result = described_class.new(user, %w[settings profile]).execute + expect(result.length).to eq(2) + end + end + end + end +end |