summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-05-15 09:08:57 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2023-05-15 09:08:57 +0000
commit45a8c43afe8a17de19a92708b380b29b6ae04ce6 (patch)
tree4104e6ac741fbbdeefe9b8b699650a06c14e9056 /spec/models
parent6bc327a3491069240bd73cc83e17b3078c4148b0 (diff)
downloadgitlab-ce-45a8c43afe8a17de19a92708b380b29b6ae04ce6.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/blob_viewer/metrics_dashboard_yml_spec.rb16
-rw-r--r--spec/models/commit_spec.rb90
-rw-r--r--spec/models/container_registry/data_repair_detail_spec.rb18
-rw-r--r--spec/models/milestone_spec.rb8
-rw-r--r--spec/models/project_spec.rb14
5 files changed, 145 insertions, 1 deletions
diff --git a/spec/models/blob_viewer/metrics_dashboard_yml_spec.rb b/spec/models/blob_viewer/metrics_dashboard_yml_spec.rb
index d28fa0bbe97..c9ac13eefc0 100644
--- a/spec/models/blob_viewer/metrics_dashboard_yml_spec.rb
+++ b/spec/models/blob_viewer/metrics_dashboard_yml_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe BlobViewer::MetricsDashboardYml do
+RSpec.describe BlobViewer::MetricsDashboardYml, feature_category: :metrics do
include FakeBlobHelpers
include RepoHelpers
@@ -119,4 +119,18 @@ RSpec.describe BlobViewer::MetricsDashboardYml do
expect(viewer.errors).to eq ["YAML syntax: The parsed YAML is too big"]
end
end
+
+ describe '.can_render?' do
+ subject { described_class.can_render?(blob) }
+
+ it { is_expected.to be false }
+
+ context 'when metrics dashboard feature is available' do
+ before do
+ stub_feature_flags(remove_monitor_metrics: false)
+ end
+
+ it { is_expected.to be true }
+ end
+ end
end
diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb
index df630d6336c..edb856d34df 100644
--- a/spec/models/commit_spec.rb
+++ b/spec/models/commit_spec.rb
@@ -885,4 +885,94 @@ eos
expect(commit.has_been_reverted?(user, issue.notes_with_associations)).to eq(false)
end
end
+
+ describe '#tipping_refs' do
+ let_it_be(:tag_name) { 'v1.1.0' }
+ let_it_be(:branch_names) { %w[master not-merged-branch v1.1.0] }
+
+ shared_examples 'tipping ref names' do
+ context 'when called without limits' do
+ it 'return tipping refs names' do
+ expect(called_method.call).to eq(expected)
+ end
+ end
+
+ context 'when called with limits' do
+ it 'return tipping refs names' do
+ limit = 1
+ expect(called_method.call(limit).size).to be <= limit
+ end
+ end
+
+ describe '#tipping_branches' do
+ let(:called_method) { ->(limit = 0) { commit.tipping_branches(limit: limit) } }
+ let(:expected) { branch_names }
+
+ it_behaves_like 'with tipping ref names'
+ end
+
+ describe '#tipping_tags' do
+ let(:called_method) { ->(limit = 0) { commit.tipping_tags(limit: limit) } }
+ let(:expected) { [tag_name] }
+
+ it_behaves_like 'with tipping ref names'
+ end
+ end
+ end
+
+ context 'containing refs' do
+ shared_examples 'containing ref names' do
+ context 'without arguments' do
+ it 'returns branch names containing the commit' do
+ expect(ref_containing.call).to eq(containing_refs)
+ end
+ end
+
+ context 'with limit argument' do
+ it 'returns the appropriate amount branch names' do
+ limit = 2
+ expect(ref_containing.call(limit: limit).size).to be <= limit
+ end
+ end
+
+ context 'with tipping refs excluded' do
+ let(:excluded_refs) do
+ project.repository.refs_by_oid(oid: commit_sha, ref_patterns: [ref_prefix]).map { |n| n.delete_prefix(ref_prefix) }
+ end
+
+ it 'returns branch names containing the commit without the one with the commit at tip' do
+ expect(ref_containing.call(excluded_tipped: true)).to eq(containing_refs - excluded_refs)
+ end
+
+ it 'returns the appropriate amount branch names with limit argument' do
+ limit = 2
+ expect(ref_containing.call(limit: limit, excluded_tipped: true).size).to be <= limit
+ end
+ end
+ end
+
+ describe '#branches_containing' do
+ let_it_be(:commit_sha) { project.commit.sha }
+ let_it_be(:containing_refs) { project.repository.branch_names_contains(commit_sha) }
+
+ let(:ref_prefix) { Gitlab::Git::BRANCH_REF_PREFIX }
+
+ let(:ref_containing) { ->(limit: 0, excluded_tipped: false) { commit.branches_containing(exclude_tipped: excluded_tipped, limit: limit) } }
+
+ it_behaves_like 'containing ref names'
+ end
+
+ describe '#tags_containing' do
+ let_it_be(:tag_name) { 'v1.1.0' }
+ let_it_be(:commit_sha) { project.repository.find_tag(tag_name).target_commit.sha }
+ let_it_be(:containing_refs) { %w[v1.1.0 v1.1.1] }
+
+ let(:ref_prefix) { Gitlab::Git::TAG_REF_PREFIX }
+
+ let(:commit) { project.repository.commit(commit_sha) }
+ let(:ref_containing) { ->(limit: 0, excluded_tipped: false) { commit.tags_containing(exclude_tipped: excluded_tipped, limit: limit) } }
+
+ it_behaves_like 'containing ref names'
+ end
+ end
end
diff --git a/spec/models/container_registry/data_repair_detail_spec.rb b/spec/models/container_registry/data_repair_detail_spec.rb
index 92833553a1e..4d2ac5fff42 100644
--- a/spec/models/container_registry/data_repair_detail_spec.rb
+++ b/spec/models/container_registry/data_repair_detail_spec.rb
@@ -8,4 +8,22 @@ RSpec.describe ContainerRegistry::DataRepairDetail, type: :model, feature_catego
subject { described_class.new(project: project) }
it { is_expected.to belong_to(:project).required }
+
+ it_behaves_like 'having unique enum values'
+
+ describe '.ongoing_since' do
+ let_it_be(:repair_detail1) { create(:container_registry_data_repair_detail, :ongoing, updated_at: 1.day.ago) }
+ let_it_be(:repair_detail2) { create(:container_registry_data_repair_detail, :ongoing, updated_at: 20.minutes.ago) }
+ let_it_be(:repair_detail3) do
+ create(:container_registry_data_repair_detail, :completed, updated_at: 20.minutes.ago)
+ end
+
+ let_it_be(:repair_detail4) do
+ create(:container_registry_data_repair_detail, :completed, updated_at: 31.minutes.ago)
+ end
+
+ subject { described_class.ongoing_since(30.minutes.ago) }
+
+ it { is_expected.to contain_exactly(repair_detail1) }
+ end
end
diff --git a/spec/models/milestone_spec.rb b/spec/models/milestone_spec.rb
index 8bd7c057a6e..1c43eafb576 100644
--- a/spec/models/milestone_spec.rb
+++ b/spec/models/milestone_spec.rb
@@ -724,4 +724,12 @@ RSpec.describe Milestone do
end
end
end
+
+ describe '#lock_version' do
+ let_it_be(:milestone) { create(:milestone, project: project) }
+
+ it 'ensures that lock_version and optimistic locking is enabled' do
+ expect(milestone.lock_version).to be_present
+ end
+ end
end
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 855c5f66554..e9bb01f4b23 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -95,6 +95,7 @@ RSpec.describe Project, factory_default: :keep, feature_category: :projects do
it { is_expected.to have_one(:mock_ci_integration) }
it { is_expected.to have_one(:mock_monitoring_integration) }
it { is_expected.to have_one(:service_desk_custom_email_verification).class_name('ServiceDesk::CustomEmailVerification') }
+ it { is_expected.to have_one(:container_registry_data_repair_detail).class_name('ContainerRegistry::DataRepairDetail') }
it { is_expected.to have_many(:commit_statuses) }
it { is_expected.to have_many(:ci_pipelines) }
it { is_expected.to have_many(:ci_refs) }
@@ -6800,6 +6801,19 @@ RSpec.describe Project, factory_default: :keep, feature_category: :projects do
end
end
+ describe '.pending_data_repair_analysis' do
+ it 'returns projects that are not in ContainerRegistry::DataRepairDetail' do
+ project_1 = create(:project)
+ project_2 = create(:project)
+
+ expect(described_class.pending_data_repair_analysis).to match_array([project_1, project_2])
+
+ create(:container_registry_data_repair_detail, project: project_1)
+
+ expect(described_class.pending_data_repair_analysis).to match_array([project_2])
+ end
+ end
+
describe '.deployments' do
subject { project.deployments }