diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/models/project_spec.rb | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/models/project_spec.rb')
-rw-r--r-- | spec/models/project_spec.rb | 217 |
1 files changed, 206 insertions, 11 deletions
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 8fdda241719..f589589af8f 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -61,7 +61,6 @@ RSpec.describe Project do it { is_expected.to have_one(:youtrack_service) } it { is_expected.to have_one(:custom_issue_tracker_service) } it { is_expected.to have_one(:bugzilla_service) } - it { is_expected.to have_one(:gitlab_issue_tracker_service) } it { is_expected.to have_one(:external_wiki_service) } it { is_expected.to have_one(:confluence_service) } it { is_expected.to have_one(:project_feature) } @@ -104,6 +103,7 @@ RSpec.describe Project do it { is_expected.to have_many(:clusters) } it { is_expected.to have_many(:management_clusters).class_name('Clusters::Cluster') } it { is_expected.to have_many(:kubernetes_namespaces) } + it { is_expected.to have_many(:cluster_agents).class_name('Clusters::Agent') } it { is_expected.to have_many(:custom_attributes).class_name('ProjectCustomAttribute') } it { is_expected.to have_many(:project_badges).class_name('ProjectBadge') } it { is_expected.to have_many(:lfs_file_locks) } @@ -122,6 +122,7 @@ RSpec.describe Project do it { is_expected.to have_many(:reviews).inverse_of(:project) } it { is_expected.to have_many(:packages).class_name('Packages::Package') } it { is_expected.to have_many(:package_files).class_name('Packages::PackageFile') } + it { is_expected.to have_many(:pipeline_artifacts) } it_behaves_like 'model with repository' do let_it_be(:container) { create(:project, :repository, path: 'somewhere') } @@ -400,6 +401,7 @@ RSpec.describe Project do create(:project, pending_delete: true) end + let(:new_project) do build(:project, name: project_pending_deletion.name, @@ -474,6 +476,46 @@ RSpec.describe Project do end end + describe '#has_packages?' do + let(:project) { create(:project, :public) } + + subject { project.has_packages?(package_type) } + + shared_examples 'returning true examples' do + let!(:package) { create("#{package_type}_package", project: project) } + + it { is_expected.to be true } + end + + shared_examples 'returning false examples' do + it { is_expected.to be false } + end + + context 'with maven packages' do + it_behaves_like 'returning true examples' do + let(:package_type) { :maven } + end + end + + context 'with npm packages' do + it_behaves_like 'returning true examples' do + let(:package_type) { :npm } + end + end + + context 'with conan packages' do + it_behaves_like 'returning true examples' do + let(:package_type) { :conan } + end + end + + context 'with no package type' do + it_behaves_like 'returning false examples' do + let(:package_type) { nil } + end + end + end + describe '#ci_pipelines' do let(:project) { create(:project) } @@ -638,6 +680,12 @@ RSpec.describe Project do end end end + + context 'when argument is a user' do + it 'returns full path to the project' do + expect(project.to_reference_base(owner)).to eq 'sample-namespace/sample-project' + end + end end describe '#to_human_reference' do @@ -1042,6 +1090,30 @@ RSpec.describe Project do end end + describe '#default_owner' do + let_it_be(:owner) { create(:user) } + let_it_be(:namespace) { create(:namespace, owner: owner) } + + context 'the project does not have a group' do + let(:project) { build(:project, namespace: namespace) } + + it 'is the namespace owner' do + expect(project.default_owner).to eq(owner) + end + end + + context 'the project is in a group' do + let(:group) { build(:group) } + let(:project) { build(:project, group: group, namespace: namespace) } + + it 'is the group owner' do + allow(group).to receive(:default_owner).and_return(Object.new) + + expect(project.default_owner).to eq(group.default_owner) + end + end + end + describe '#external_wiki' do let(:project) { create(:project) } @@ -1408,16 +1480,69 @@ RSpec.describe Project do end describe '#service_desk_address' do - let_it_be(:project) { create(:project, service_desk_enabled: true) } + let_it_be(:project, reload: true) { create(:project, service_desk_enabled: true) } - before do - allow(Gitlab::ServiceDesk).to receive(:enabled?).and_return(true) - allow(Gitlab.config.incoming_email).to receive(:enabled).and_return(true) - allow(Gitlab.config.incoming_email).to receive(:address).and_return("test+%{key}@mail.com") + subject { project.service_desk_address } + + shared_examples 'with incoming email address' do + context 'when incoming email is enabled' do + before do + config = double(enabled: true, address: 'test+%{key}@mail.com') + allow(::Gitlab.config).to receive(:incoming_email).and_return(config) + end + + it 'uses project full path as service desk address key' do + expect(project.service_desk_address).to eq("test+#{project.full_path_slug}-#{project.project_id}-issue-@mail.com") + end + end + + context 'when incoming email is disabled' do + before do + config = double(enabled: false) + allow(::Gitlab.config).to receive(:incoming_email).and_return(config) + end + + it 'uses project full path as service desk address key' do + expect(project.service_desk_address).to be_nil + end + end + end + + context 'when service_desk_email is disabled' do + before do + allow(::Gitlab::ServiceDeskEmail).to receive(:enabled?).and_return(false) + end + + it_behaves_like 'with incoming email address' end - it 'uses project full path as service desk address key' do - expect(project.service_desk_address).to eq("test+#{project.full_path_slug}-#{project.project_id}-issue-@mail.com") + context 'when service_desk_email is enabled' do + before do + config = double(enabled: true, address: 'foo+%{key}@bar.com') + allow(::Gitlab::ServiceDeskEmail).to receive(:config).and_return(config) + end + + context 'when service_desk_custom_address flag is enabled' do + before do + stub_feature_flags(service_desk_custom_address: true) + end + + it 'returns custom address when project_key is set' do + create(:service_desk_setting, project: project, project_key: 'key1') + + expect(subject).to eq("foo+#{project.full_path_slug}-key1@bar.com") + end + + it_behaves_like 'with incoming email address' + end + + context 'when service_desk_custom_address flag is disabled' do + before do + stub_feature_flags(service_desk_custom_address: false) + end + + it_behaves_like 'with incoming email address' + end end end @@ -1657,9 +1782,9 @@ RSpec.describe Project do subject { project.pages_deployed? } - context 'if public folder does exist' do + context 'if pages are deployed' do before do - allow(Dir).to receive(:exist?).with(project.public_pages_path).and_return(true) + project.pages_metadatum.update_column(:deployed, true) end it { is_expected.to be_truthy } @@ -2221,6 +2346,7 @@ RSpec.describe Project do create(:ci_empty_pipeline, project: project, sha: project.commit.id, ref: project.default_branch) end + let!(:pipeline_for_second_branch) do create(:ci_empty_pipeline, project: project, sha: second_branch.target, ref: second_branch.name) @@ -3488,6 +3614,7 @@ RSpec.describe Project do public: '\\1' MAP end + let(:sha) { project.commit.id } context 'when there is a route map' do @@ -4085,7 +4212,6 @@ RSpec.describe Project do end it 'removes the pages directory and marks the project as not having pages deployed' do - expect_any_instance_of(Projects::UpdatePagesConfigurationService).to receive(:execute) expect_any_instance_of(Gitlab::PagesTransfer).to receive(:rename_project).and_return(true) expect(PagesWorker).to receive(:perform_in).with(5.minutes, :remove, namespace.full_path, anything) @@ -5105,6 +5231,7 @@ RSpec.describe Project do allow_collaboration: true ) end + let!(:merge_request) do create( :merge_request, @@ -5455,6 +5582,32 @@ RSpec.describe Project do end end + describe '.for_repository_storage' do + it 'returns the projects for a given repository storage' do + stub_storage_settings('test_second_storage' => { + 'path' => TestEnv::SECOND_STORAGE_PATH, + 'gitaly_address' => Gitlab.config.repositories.storages.default.gitaly_address + }) + expected_project = create(:project, repository_storage: 'default') + create(:project, repository_storage: 'test_second_storage') + + expect(described_class.for_repository_storage('default')).to eq([expected_project]) + end + end + + describe '.excluding_repository_storage' do + it 'returns the projects excluding the given repository storage' do + stub_storage_settings('test_second_storage' => { + 'path' => TestEnv::SECOND_STORAGE_PATH, + 'gitaly_address' => Gitlab.config.repositories.storages.default.gitaly_address + }) + expected_project = create(:project, repository_storage: 'test_second_storage') + create(:project, repository_storage: 'default') + + expect(described_class.excluding_repository_storage('default')).to eq([expected_project]) + end + end + describe '.deployments' do subject { project.deployments } @@ -6154,6 +6307,48 @@ RSpec.describe Project do end end + describe '#has_packages?' do + let(:project) { create(:project, :public) } + + subject { project.has_packages?(package_type) } + + shared_examples 'has_package' do + context 'package of package_type exists' do + let!(:package) { create("#{package_type}_package", project: project) } + + it { is_expected.to be true } + end + + context 'package of package_type does not exist' do + it { is_expected.to be false } + end + end + + context 'with maven packages' do + it_behaves_like 'has_package' do + let(:package_type) { :maven } + end + end + + context 'with npm packages' do + it_behaves_like 'has_package' do + let(:package_type) { :npm } + end + end + + context 'with conan packages' do + it_behaves_like 'has_package' do + let(:package_type) { :conan } + end + end + + context 'calling has_package? with nil' do + let(:package_type) { nil } + + it { is_expected.to be false } + end + end + describe '#environments_for_scope' do let_it_be(:project, reload: true) { create(:project) } |