diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-17 00:12:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-17 00:12:07 +0300 |
commit | 2571f434015308eccb425059ad5e82851521265a (patch) | |
tree | a323b0a704a287e8e94d25e2480f321d13bab6cc /spec/models | |
parent | 8a9790b0db723db32f8dff511ee032e5e8e3b583 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
21 files changed, 45 insertions, 0 deletions
diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb index c3ddb22de14..16e1d8fbc4d 100644 --- a/spec/models/application_setting_spec.rb +++ b/spec/models/application_setting_spec.rb @@ -116,6 +116,7 @@ RSpec.describe ApplicationSetting do it { is_expected.to validate_presence_of(:max_yaml_depth) } it { is_expected.to validate_numericality_of(:max_yaml_depth).only_integer.is_greater_than(0) } it { is_expected.to validate_presence_of(:max_pages_size) } + it 'ensures max_pages_size is an integer greater than 0 (or equal to 0 to indicate unlimited/maximum)' do is_expected.to validate_numericality_of(:max_pages_size).only_integer.is_greater_than_or_equal_to(0) .is_less_than(::Gitlab::Pages::MAX_SIZE / 1.megabyte) diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index c0cea29941e..0c28c99c113 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -844,6 +844,7 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do it 'has 8 items' do expect(subject.size).to eq(8) end + it { expect(pipeline.sha).to start_with(subject) } end diff --git a/spec/models/ci/secure_file_spec.rb b/spec/models/ci/secure_file_spec.rb index a3f1c7b7ef7..e47efff5dfd 100644 --- a/spec/models/ci/secure_file_spec.rb +++ b/spec/models/ci/secure_file_spec.rb @@ -26,6 +26,7 @@ RSpec.describe Ci::SecureFile do it { is_expected.to validate_presence_of(:file_store) } it { is_expected.to validate_presence_of(:name) } it { is_expected.to validate_presence_of(:project_id) } + context 'unique filename' do let_it_be(:project1) { create(:project) } diff --git a/spec/models/concerns/expirable_spec.rb b/spec/models/concerns/expirable_spec.rb index 5eb6530881e..50dfb138ac9 100644 --- a/spec/models/concerns/expirable_spec.rb +++ b/spec/models/concerns/expirable_spec.rb @@ -16,6 +16,11 @@ RSpec.describe Expirable do it { expect(ProjectMember.expired).to match_array([expired]) } end + describe '.not_expired' do + it { expect(ProjectMember.not_expired).to include(no_expire, expire_later) } + it { expect(ProjectMember.not_expired).not_to include(expired) } + end + describe '#expired?' do it { expect(no_expire.expired?).to eq(false) } it { expect(expire_later.expired?).to eq(false) } diff --git a/spec/models/deploy_key_spec.rb b/spec/models/deploy_key_spec.rb index 8c3b02427ae..3272d5236d3 100644 --- a/spec/models/deploy_key_spec.rb +++ b/spec/models/deploy_key_spec.rb @@ -5,17 +5,20 @@ require 'spec_helper' RSpec.describe DeployKey, :mailer do describe "Associations" do it { is_expected.to have_many(:deploy_keys_projects) } + it do is_expected.to have_many(:deploy_keys_projects_with_write_access) .conditions(can_push: true) .class_name('DeployKeysProject') end + it do is_expected.to have_many(:projects_with_write_access) .class_name('Project') .through(:deploy_keys_projects_with_write_access) .source(:project) end + it { is_expected.to have_many(:projects) } it { is_expected.to have_many(:protected_branch_push_access_levels) } end diff --git a/spec/models/incident_management/issuable_escalation_status_spec.rb b/spec/models/incident_management/issuable_escalation_status_spec.rb index 39d1fb325f5..f87e6e8327a 100644 --- a/spec/models/incident_management/issuable_escalation_status_spec.rb +++ b/spec/models/incident_management/issuable_escalation_status_spec.rb @@ -11,6 +11,7 @@ RSpec.describe IncidentManagement::IssuableEscalationStatus do describe 'associations' do it { is_expected.to belong_to(:issue) } + it do is_expected.to have_one(:project).through(:issue).inverse_of(:incident_management_issuable_escalation_statuses) end diff --git a/spec/models/integrations/bamboo_spec.rb b/spec/models/integrations/bamboo_spec.rb index 574b87d6c60..e92226d109f 100644 --- a/spec/models/integrations/bamboo_spec.rb +++ b/spec/models/integrations/bamboo_spec.rb @@ -33,6 +33,7 @@ RSpec.describe Integrations::Bamboo, :use_clean_rails_memory_store_caching do it { is_expected.to validate_presence_of(:build_key) } it { is_expected.to validate_presence_of(:bamboo_url) } + it_behaves_like 'issue tracker integration URL attribute', :bamboo_url describe '#username' do diff --git a/spec/models/integrations/bugzilla_spec.rb b/spec/models/integrations/bugzilla_spec.rb index 432306c8fa8..f05bc26d066 100644 --- a/spec/models/integrations/bugzilla_spec.rb +++ b/spec/models/integrations/bugzilla_spec.rb @@ -12,6 +12,7 @@ RSpec.describe Integrations::Bugzilla do it { is_expected.to validate_presence_of(:project_url) } it { is_expected.to validate_presence_of(:issues_url) } it { is_expected.to validate_presence_of(:new_issue_url) } + it_behaves_like 'issue tracker integration URL attribute', :project_url it_behaves_like 'issue tracker integration URL attribute', :issues_url it_behaves_like 'issue tracker integration URL attribute', :new_issue_url diff --git a/spec/models/integrations/buildkite_spec.rb b/spec/models/integrations/buildkite_spec.rb index af2e587dc7b..38ceb5db49c 100644 --- a/spec/models/integrations/buildkite_spec.rb +++ b/spec/models/integrations/buildkite_spec.rb @@ -30,6 +30,7 @@ RSpec.describe Integrations::Buildkite, :use_clean_rails_memory_store_caching do it { is_expected.to validate_presence_of(:project_url) } it { is_expected.to validate_presence_of(:token) } + it_behaves_like 'issue tracker integration URL attribute', :project_url end diff --git a/spec/models/integrations/custom_issue_tracker_spec.rb b/spec/models/integrations/custom_issue_tracker_spec.rb index e1ffe7a74f0..11f98b99bbe 100644 --- a/spec/models/integrations/custom_issue_tracker_spec.rb +++ b/spec/models/integrations/custom_issue_tracker_spec.rb @@ -12,6 +12,7 @@ RSpec.describe Integrations::CustomIssueTracker do it { is_expected.to validate_presence_of(:project_url) } it { is_expected.to validate_presence_of(:issues_url) } it { is_expected.to validate_presence_of(:new_issue_url) } + it_behaves_like 'issue tracker integration URL attribute', :project_url it_behaves_like 'issue tracker integration URL attribute', :issues_url it_behaves_like 'issue tracker integration URL attribute', :new_issue_url diff --git a/spec/models/integrations/drone_ci_spec.rb b/spec/models/integrations/drone_ci_spec.rb index 5ae4af1a665..8a51f8a0705 100644 --- a/spec/models/integrations/drone_ci_spec.rb +++ b/spec/models/integrations/drone_ci_spec.rb @@ -19,6 +19,7 @@ RSpec.describe Integrations::DroneCi, :use_clean_rails_memory_store_caching do it { is_expected.to validate_presence_of(:token) } it { is_expected.to validate_presence_of(:drone_url) } + it_behaves_like 'issue tracker integration URL attribute', :drone_url end diff --git a/spec/models/integrations/ewm_spec.rb b/spec/models/integrations/ewm_spec.rb index 49681fefe55..dc48a2c982f 100644 --- a/spec/models/integrations/ewm_spec.rb +++ b/spec/models/integrations/ewm_spec.rb @@ -12,6 +12,7 @@ RSpec.describe Integrations::Ewm do it { is_expected.to validate_presence_of(:project_url) } it { is_expected.to validate_presence_of(:issues_url) } it { is_expected.to validate_presence_of(:new_issue_url) } + it_behaves_like 'issue tracker integration URL attribute', :project_url it_behaves_like 'issue tracker integration URL attribute', :issues_url it_behaves_like 'issue tracker integration URL attribute', :new_issue_url diff --git a/spec/models/integrations/external_wiki_spec.rb b/spec/models/integrations/external_wiki_spec.rb index 1621605d39f..8644e20690c 100644 --- a/spec/models/integrations/external_wiki_spec.rb +++ b/spec/models/integrations/external_wiki_spec.rb @@ -10,6 +10,7 @@ RSpec.describe Integrations::ExternalWiki do end it { is_expected.to validate_presence_of(:external_wiki_url) } + it_behaves_like 'issue tracker integration URL attribute', :external_wiki_url end diff --git a/spec/models/integrations/microsoft_teams_spec.rb b/spec/models/integrations/microsoft_teams_spec.rb index af6c142525c..b1b3e42b5e9 100644 --- a/spec/models/integrations/microsoft_teams_spec.rb +++ b/spec/models/integrations/microsoft_teams_spec.rb @@ -24,6 +24,7 @@ RSpec.describe Integrations::MicrosoftTeams do end it { is_expected.to validate_presence_of(:webhook) } + it_behaves_like 'issue tracker integration URL attribute', :webhook end diff --git a/spec/models/integrations/teamcity_spec.rb b/spec/models/integrations/teamcity_spec.rb index 046476225a6..da559264c1e 100644 --- a/spec/models/integrations/teamcity_spec.rb +++ b/spec/models/integrations/teamcity_spec.rb @@ -76,6 +76,7 @@ RSpec.describe Integrations::Teamcity, :use_clean_rails_memory_store_caching do it { is_expected.to validate_presence_of(:build_type) } it { is_expected.to validate_presence_of(:teamcity_url) } + it_behaves_like 'issue tracker integration URL attribute', :teamcity_url describe '#username' do diff --git a/spec/models/packages/cleanup/policy_spec.rb b/spec/models/packages/cleanup/policy_spec.rb index a37042520e7..0b6dff472c1 100644 --- a/spec/models/packages/cleanup/policy_spec.rb +++ b/spec/models/packages/cleanup/policy_spec.rb @@ -9,6 +9,7 @@ RSpec.describe Packages::Cleanup::Policy, type: :model do describe 'validations' do it { is_expected.to validate_presence_of(:project) } + it do is_expected .to validate_inclusion_of(:keep_n_duplicated_package_files) diff --git a/spec/models/personal_access_token_spec.rb b/spec/models/personal_access_token_spec.rb index dc3c73f9498..f3ef347121e 100644 --- a/spec/models/personal_access_token_spec.rb +++ b/spec/models/personal_access_token_spec.rb @@ -193,6 +193,20 @@ RSpec.describe PersonalAccessToken do end describe 'scopes' do + describe '.active' do + let_it_be(:revoked_token) { create(:personal_access_token, :revoked) } + let_it_be(:not_revoked_false_token) { create(:personal_access_token, revoked: false) } + let_it_be(:not_revoked_nil_token) { create(:personal_access_token, revoked: nil) } + let_it_be(:expired_token) { create(:personal_access_token, :expired) } + let_it_be(:not_expired_token) { create(:personal_access_token) } + let_it_be(:never_expires_token) { create(:personal_access_token, expires_at: nil) } + + it 'includes non-revoked and non-expired tokens' do + expect(described_class.active) + .to match_array([not_revoked_false_token, not_revoked_nil_token, not_expired_token, never_expires_token]) + end + end + describe '.expiring_and_not_notified' do let_it_be(:expired_token) { create(:personal_access_token, expires_at: 2.days.ago) } let_it_be(:revoked_token) { create(:personal_access_token, revoked: true) } diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index e107cc15b9d..945f3049282 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -6166,6 +6166,7 @@ RSpec.describe User do let(:encrypted_password) { Devise::Encryptor.digest(User, User.random_password) } it { is_expected.to be_falsey } + it_behaves_like 'not re-encrypting with PBKDF2' context 'when pbkdf2_password_encryption is disabled' do @@ -6174,6 +6175,7 @@ RSpec.describe User do end it { is_expected.to be_falsey } + it_behaves_like 'not re-encrypting with PBKDF2' end end @@ -6197,6 +6199,7 @@ RSpec.describe User do end it { is_expected.to be_truthy } + it_behaves_like 'not re-encrypting with PBKDF2' end @@ -6206,6 +6209,7 @@ RSpec.describe User do end it { is_expected.to be_truthy } + it_behaves_like 'not re-encrypting with PBKDF2' end end diff --git a/spec/models/users/in_product_marketing_email_spec.rb b/spec/models/users/in_product_marketing_email_spec.rb index 7796b54babc..78de9ad8bdb 100644 --- a/spec/models/users/in_product_marketing_email_spec.rb +++ b/spec/models/users/in_product_marketing_email_spec.rb @@ -18,6 +18,7 @@ RSpec.describe Users::InProductMarketingEmail, type: :model do context 'for a track+series email' do it { is_expected.to validate_presence_of(:track) } it { is_expected.to validate_presence_of(:series) } + it { is_expected.to validate_uniqueness_of(:user_id) .scoped_to([:track, :series]).with_message('track series email has already been sent') @@ -30,10 +31,12 @@ RSpec.describe Users::InProductMarketingEmail, type: :model do it { is_expected.to validate_presence_of(:campaign) } it { is_expected.not_to validate_presence_of(:track) } it { is_expected.not_to validate_presence_of(:series) } + it { is_expected.to validate_uniqueness_of(:user_id) .scoped_to(:campaign).with_message('campaign email has already been sent') } + it { is_expected.to validate_inclusion_of(:campaign).in_array(described_class::CAMPAIGNS) } end diff --git a/spec/models/users/project_callout_spec.rb b/spec/models/users/project_callout_spec.rb index 214568b4de3..87d865c4bdf 100644 --- a/spec/models/users/project_callout_spec.rb +++ b/spec/models/users/project_callout_spec.rb @@ -16,6 +16,7 @@ RSpec.describe Users::ProjectCallout do describe 'validations' do it { is_expected.to validate_presence_of(:project) } it { is_expected.to validate_presence_of(:feature_name) } + it { is_expected.to validate_uniqueness_of(:feature_name).scoped_to(:user_id, :project_id).ignoring_case_sensitivity } diff --git a/spec/models/webauthn_registration_spec.rb b/spec/models/webauthn_registration_spec.rb index 6813854bf6c..240e7002ca3 100644 --- a/spec/models/webauthn_registration_spec.rb +++ b/spec/models/webauthn_registration_spec.rb @@ -13,6 +13,7 @@ RSpec.describe WebauthnRegistration do it { is_expected.to validate_presence_of(:counter) } it { is_expected.to validate_length_of(:name).is_at_least(0) } it { is_expected.not_to allow_value(nil).for(:name) } + it do is_expected.to validate_numericality_of(:counter) .only_integer |