diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-22 12:17:04 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-22 12:17:04 +0300 |
commit | 6b0293c14dce817f72310127dd38562313321b1b (patch) | |
tree | cb2254757b496664957a2b5d90c21d7d76e4bdeb /spec/models | |
parent | 968a9dd39b77628b541e0788488bad2493fefbee (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/concerns/commit_signature_spec.rb | 22 | ||||
-rw-r--r-- | spec/models/group_spec.rb | 42 | ||||
-rw-r--r-- | spec/models/namespace_spec.rb | 1 | ||||
-rw-r--r-- | spec/models/organizations/organization_user_spec.rb | 14 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 11 |
5 files changed, 83 insertions, 7 deletions
diff --git a/spec/models/concerns/commit_signature_spec.rb b/spec/models/concerns/commit_signature_spec.rb index 4bba5a6ee41..9a4ac165ac1 100644 --- a/spec/models/concerns/commit_signature_spec.rb +++ b/spec/models/concerns/commit_signature_spec.rb @@ -2,15 +2,15 @@ require 'spec_helper' -RSpec.describe CommitSignature do +RSpec.describe CommitSignature, feature_category: :source_code_management do + subject(:implementation) do + Class.new(ActiveRecord::Base) do + self.table_name = 'ssh_signatures' + end.include(described_class).new + end + describe '#signed_by_user' do context 'when class does not define the signed_by_user method' do - subject(:implementation) do - Class.new(ActiveRecord::Base) do - self.table_name = 'ssh_signatures' - end.include(described_class).new - end - it 'raises a NoMethodError with custom message' do expect do implementation.signed_by_user @@ -18,4 +18,12 @@ RSpec.describe CommitSignature do end end end + + describe 'enums' do + it 'defines enums for verification statuses' do + is_expected.to define_enum_for(:verification_status).with_values( + ::Enums::CommitSignature.verification_statuses + ) + end + end end diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index fdbcd84d3df..cf8a496afcd 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -3208,6 +3208,48 @@ RSpec.describe Group, feature_category: :groups_and_projects do end end + describe '.descendant_groups_counts' do + let_it_be(:parent) { create(:group) } + let_it_be(:group) { create(:group, parent: parent) } + let_it_be(:project) { create(:project, namespace: parent) } + + subject(:descendant_groups_counts) { described_class.id_in(parent).descendant_groups_counts } + + it 'return a hash of group id and descendant groups count without projects' do + expect(descendant_groups_counts).to eq({ parent.id => 1 }) + end + end + + describe '.projects_counts' do + let_it_be(:parent) { create(:group) } + let_it_be(:group) { create(:group, parent: parent) } + let_it_be(:project) { create(:project, namespace: parent) } + let_it_be(:archived_project) { create(:project, :archived, namespace: parent) } + + subject(:projects_counts) { described_class.id_in(parent).projects_counts } + + it 'return a hash of group id and projects count without counting archived projects' do + expect(projects_counts).to eq({ parent.id => 1 }) + end + end + + describe '.group_members_counts' do + let_it_be(:parent) { create(:group) } + let_it_be(:group) { create(:group, parent: parent) } + + before_all do + create(:group_member, group: parent) + create(:group_member, group: parent, requested_at: Time.current) + create(:group_member, group: group) + end + + subject(:group_members_counts) { described_class.id_in(parent).group_members_counts } + + it 'return a hash of group id and approved direct group members' do + expect(group_members_counts).to eq({ parent.id => 1 }) + end + end + describe '#shared_with_group_links_visible_to_user' do let_it_be(:admin) { create :admin } let_it_be(:normal_user) { create :user } diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb index 45ebde13a00..5665bce8f08 100644 --- a/spec/models/namespace_spec.rb +++ b/spec/models/namespace_spec.rb @@ -39,6 +39,7 @@ RSpec.describe Namespace, feature_category: :groups_and_projects do it { is_expected.to have_many(:namespace_commit_emails).class_name('Users::NamespaceCommitEmail') } it { is_expected.to have_many(:cycle_analytics_stages) } it { is_expected.to have_many(:value_streams) } + it { is_expected.to have_many(:non_archived_projects).class_name('Project') } it do is_expected.to have_one(:ci_cd_settings).class_name('NamespaceCiCdSetting').inverse_of(:namespace).autosave(true) diff --git a/spec/models/organizations/organization_user_spec.rb b/spec/models/organizations/organization_user_spec.rb index 392ffa1b5be..9a2f11e0654 100644 --- a/spec/models/organizations/organization_user_spec.rb +++ b/spec/models/organizations/organization_user_spec.rb @@ -7,4 +7,18 @@ RSpec.describe Organizations::OrganizationUser, type: :model, feature_category: it { is_expected.to belong_to(:organization).inverse_of(:organization_users).required } it { is_expected.to belong_to(:user).inverse_of(:organization_users).required } end + + context 'with loose foreign key on organization_users.organization_id' do + it_behaves_like 'cleanup by a loose foreign key' do + let_it_be(:parent) { create(:organization) } + let_it_be(:model) { create(:organization_user, organization: parent) } + end + end + + context 'with loose foreign key on organization_users.user_id' do + it_behaves_like 'cleanup by a loose foreign key' do + let_it_be(:parent) { create(:user) } + let_it_be(:model) { create(:organization_user, user: parent) } + end + end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 69fdec0fc10..77ceee3b1b0 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -222,6 +222,17 @@ RSpec.describe User, feature_category: :user_profile do is_expected.to have_many(:alert_assignees).class_name('::AlertManagement::AlertAssignee').inverse_of(:assignee) end + describe 'organizations association' do + it 'does not create a cross-database query' do + user = create(:user) + create(:organization_user, user: user) + + with_cross_joins_prevented do + expect(user.organizations.count).to eq(1) + end + end + end + describe 'default values' do let(:user) { described_class.new } |