diff options
author | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 13:34:23 -0600 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 13:34:23 -0600 |
commit | 6438df3a1e0fb944485cebf07976160184697d72 (patch) | |
tree | 00b09bfd170e77ae9391b1a2f5a93ef6839f2597 /spec/finders/packages/nuget/package_finder_spec.rb | |
parent | 42bcd54d971da7ef2854b896a7b34f4ef8601067 (diff) | |
download | gitlab-ce-6438df3a1e0fb944485cebf07976160184697d72.tar.gz |
Add latest changes from gitlab-org/gitlab@13-8-stable-eev13.8.0-rc42
Diffstat (limited to 'spec/finders/packages/nuget/package_finder_spec.rb')
-rw-r--r-- | spec/finders/packages/nuget/package_finder_spec.rb | 119 |
1 files changed, 81 insertions, 38 deletions
diff --git a/spec/finders/packages/nuget/package_finder_spec.rb b/spec/finders/packages/nuget/package_finder_spec.rb index 9295d0c7a2f..10b5f6c8ec2 100644 --- a/spec/finders/packages/nuget/package_finder_spec.rb +++ b/spec/finders/packages/nuget/package_finder_spec.rb @@ -2,74 +2,117 @@ require 'spec_helper' RSpec.describe Packages::Nuget::PackageFinder do - let_it_be(:package1) { create(:nuget_package) } - let_it_be(:project) { package1.project } + let_it_be(:user) { create(:user) } + let_it_be(:group) { create(:group) } + let_it_be(:subgroup) { create(:group, parent: group) } + let_it_be(:project) { create(:project, namespace: subgroup) } + let_it_be(:package1) { create(:nuget_package, project: project) } let_it_be(:package2) { create(:nuget_package, name: package1.name, version: '2.0.0', project: project) } let_it_be(:package3) { create(:nuget_package, name: 'Another.Dummy.Package', project: project) } + let_it_be(:other_package_1) { create(:nuget_package, name: package1.name, version: package1.version) } + let_it_be(:other_package_2) { create(:nuget_package, name: package1.name, version: package2.version) } let(:package_name) { package1.name } let(:package_version) { nil } let(:limit) { 50 } describe '#execute!' do - subject { described_class.new(project, package_name: package_name, package_version: package_version, limit: limit).execute } + subject { described_class.new(user, target, package_name: package_name, package_version: package_version, limit: limit).execute } - it { is_expected.to match_array([package1, package2]) } + shared_examples 'handling all the conditions' do + it { is_expected.to match_array([package1, package2]) } - context 'with lower case package name' do - let(:package_name) { package1.name.downcase } + context 'with lower case package name' do + let(:package_name) { package1.name.downcase } - it { is_expected.to match_array([package1, package2]) } - end + it { is_expected.to match_array([package1, package2]) } + end - context 'with unknown package name' do - let(:package_name) { 'foobar' } + context 'with unknown package name' do + let(:package_name) { 'foobar' } - it { is_expected.to be_empty } - end + it { is_expected.to be_empty } + end - context 'with valid version' do - let(:package_version) { '2.0.0' } + context 'with valid version' do + let(:package_version) { '2.0.0' } - it { is_expected.to match_array([package2]) } - end + it { is_expected.to match_array([package2]) } + end - context 'with unknown version' do - let(:package_version) { 'foobar' } + context 'with unknown version' do + let(:package_version) { 'foobar' } - it { is_expected.to be_empty } - end + it { is_expected.to be_empty } + end + + context 'with limit hit' do + let_it_be(:package4) { create(:nuget_package, name: package1.name, project: project) } + let_it_be(:package5) { create(:nuget_package, name: package1.name, project: project) } + let_it_be(:package6) { create(:nuget_package, name: package1.name, project: project) } + let(:limit) { 2 } + + it { is_expected.to match_array([package5, package6]) } + end + + context 'with downcase package name' do + let(:package_name) { package1.name.downcase } + + it { is_expected.to match_array([package1, package2]) } + end - context 'with limit hit' do - let_it_be(:package4) { create(:nuget_package, name: package1.name, project: project) } - let_it_be(:package5) { create(:nuget_package, name: package1.name, project: project) } - let_it_be(:package6) { create(:nuget_package, name: package1.name, project: project) } - let(:limit) { 2 } + context 'with prefix wildcard' do + let(:package_name) { "%#{package1.name[3..-1]}" } - it { is_expected.to match_array([package5, package6]) } + it { is_expected.to match_array([package1, package2]) } + end + + context 'with suffix wildcard' do + let(:package_name) { "#{package1.name[0..-3]}%" } + + it { is_expected.to match_array([package1, package2]) } + end + + context 'with surrounding wildcards' do + let(:package_name) { "%#{package1.name[3..-3]}%" } + + it { is_expected.to match_array([package1, package2]) } + end end - context 'with downcase package name' do - let(:package_name) { package1.name.downcase } + context 'with a project' do + let(:target) { project } - it { is_expected.to match_array([package1, package2]) } + before do + project.add_developer(user) + end + + it_behaves_like 'handling all the conditions' end - context 'with prefix wildcard' do - let(:package_name) { "%#{package1.name[3..-1]}" } + context 'with a subgroup' do + let(:target) { subgroup } - it { is_expected.to match_array([package1, package2]) } + before do + subgroup.add_developer(user) + end + + it_behaves_like 'handling all the conditions' end - context 'with suffix wildcard' do - let(:package_name) { "#{package1.name[0..-3]}%" } + context 'with a group' do + let(:target) { group } - it { is_expected.to match_array([package1, package2]) } + before do + group.add_developer(user) + end + + it_behaves_like 'handling all the conditions' end - context 'with surrounding wildcards' do - let(:package_name) { "%#{package1.name[3..-3]}%" } + context 'with nil' do + let(:target) { nil } - it { is_expected.to match_array([package1, package2]) } + it { is_expected.to be_empty } end end end |