Skip to content
Snippets Groups Projects
Commit 4289c903 authored by Jessie Young's avatar Jessie Young ❣️
Browse files

Merge branch 'refactor-boolean-validation-specs' into 'master'

Refactors boolean validation specs using 'validate_inclusion_of'

See merge request !133073



Merged-by: Jessie Young's avatarJessie Young <jessieyoung@gitlab.com>
Approved-by: Jessie Young's avatarJessie Young <jessieyoung@gitlab.com>
Co-authored-by: default avatarHarshit Prasad <harshitprasad28@gmail.com>
parents 1d0b5ed4 d312e9a9
No related branches found
No related tags found
1 merge request!133073Refactors boolean validation specs using 'validate_inclusion_of'
Pipeline #1023693280 passed with warnings
Pipeline: E2E Omnibus GitLab EE

#1023745986

    Pipeline: GitLab

    #1023695821

      Pipeline: E2E GDK

      #1023694655

        +21
        Showing
        with 42 additions and 79 deletions
        ......@@ -103,8 +103,7 @@
        it { is_expected.to allow_value('a' * 255).for(:elasticsearch_username) }
        it { is_expected.not_to allow_value('a' * 256).for(:elasticsearch_username) }
        it { is_expected.to allow_value(true, false).for(:security_policy_global_group_approvers_enabled) }
        it { is_expected.not_to allow_value(nil).for(:security_policy_global_group_approvers_enabled) }
        it { is_expected.to validate_inclusion_of(:security_policy_global_group_approvers_enabled).in_array([true, false]) }
        end
        describe 'future_subscriptions', feature_category: :subscription_management do
        ......@@ -167,12 +166,10 @@
        describe 'dashboard', feature_category: :metrics do
        it { is_expected.to validate_numericality_of(:dashboard_limit).only_integer.is_greater_than_or_equal_to(0) }
        it { is_expected.to allow_value(true, false).for(:dashboard_limit_enabled) }
        it { is_expected.not_to allow_value(nil).for(:dashboard_limit_enabled) }
        it { is_expected.to validate_inclusion_of(:dashboard_limit_enabled).in_array([true, false]) }
        end
        it { is_expected.to allow_value(true, false).for(:allow_account_deletion) }
        it { is_expected.not_to allow_value(nil).for(:allow_account_deletion) }
        it { is_expected.to validate_inclusion_of(:allow_account_deletion).in_array([true, false]) }
        describe 'when additional email text is enabled', feature_category: :user_profile do
        before do
        ......@@ -477,7 +474,7 @@
        stub_application_setting_enum('email_confirmation_setting', 'hard')
        end
        it { is_expected.to allow_value(true, false).for(:delete_unconfirmed_users) }
        it { is_expected.to validate_inclusion_of(:delete_unconfirmed_users).in_array([true, false]) }
        it { is_expected.to validate_numericality_of(:unconfirmed_users_delete_after_days).is_greater_than(0) }
        end
        ......@@ -489,7 +486,7 @@
        allow(Devise).to receive(:allow_unconfirmed_access_for).and_return(allow_unconfirmed_access_for.days)
        end
        it { is_expected.to allow_value(true, false).for(:delete_unconfirmed_users) }
        it { is_expected.to validate_inclusion_of(:delete_unconfirmed_users).in_array([true, false]) }
        it { is_expected.to validate_numericality_of(:unconfirmed_users_delete_after_days).is_greater_than(allow_unconfirmed_access_for) }
        end
        ......@@ -1197,7 +1194,7 @@ def expect_is_es_licensed
        expect(setting.lock_delayed_project_removal).to be false
        end
        it { is_expected.to allow_value(true, false).for(:delayed_project_removal) }
        it { is_expected.to validate_inclusion_of(:delayed_project_removal).in_array([true, false]) }
        end
        end
        ......
        ......@@ -12,17 +12,13 @@
        subject { setting }
        options = [true, false]
        it { is_expected.to validate_presence_of(:group) }
        it { is_expected.not_to allow_value(nil).for(:allow_author_approval) }
        it { is_expected.to allow_value(true, false).for(:allow_author_approval) }
        it { is_expected.not_to allow_value(nil).for(:allow_committer_approval) }
        it { is_expected.to allow_value(true, false).for(:allow_committer_approval) }
        it { is_expected.not_to allow_value(nil).for(:allow_overrides_to_approver_list_per_merge_request) }
        it { is_expected.to allow_value(true, false).for(:allow_overrides_to_approver_list_per_merge_request) }
        it { is_expected.not_to allow_value(nil).for(:retain_approvals_on_push) }
        it { is_expected.to allow_value(true, false).for(:retain_approvals_on_push) }
        it { is_expected.not_to allow_value(nil).for(:require_password_to_approve) }
        it { is_expected.to allow_value(true, false).for(:require_password_to_approve) }
        it { is_expected.to validate_inclusion_of(:allow_author_approval).in_array(options) }
        it { is_expected.to validate_inclusion_of(:allow_committer_approval).in_array(options) }
        it { is_expected.to validate_inclusion_of(:allow_overrides_to_approver_list_per_merge_request).in_array(options) }
        it { is_expected.to validate_inclusion_of(:retain_approvals_on_push).in_array(options) }
        it { is_expected.to validate_inclusion_of(:require_password_to_approve).in_array(options) }
        end
        describe '.find_or_initialize_by_group' do
        ......
        ......@@ -53,8 +53,7 @@
        allow(subject).to receive(:ai_settings_allowed?).and_return(true)
        end
        it { is_expected.to allow_value(true, false).for(attr) }
        it { is_expected.not_to allow_value(nil).for(attr) }
        it { is_expected.to validate_inclusion_of(attr).in_array([true, false]) }
        context 'when AI settings are not allowed' do
        before do
        ......@@ -79,8 +78,7 @@
        allow(subject).to receive(:ai_assist_ui_enabled?).and_return(true)
        end
        it { is_expected.to allow_value(true, false).for(:third_party_ai_features_enabled) }
        it { is_expected.not_to allow_value(nil).for(:third_party_ai_features_enabled) }
        it { is_expected.to validate_inclusion_of(:third_party_ai_features_enabled).in_array([true, false]) }
        end
        end
        end
        ......
        ......@@ -12,8 +12,7 @@
        subject { scan_result_policy_read }
        it { is_expected.not_to allow_value(nil).for(:match_on_inclusion) }
        it { is_expected.to allow_value(true, false).for(:match_on_inclusion) }
        it { is_expected.to validate_inclusion_of(:match_on_inclusion).in_array([true, false]) }
        it { is_expected.not_to allow_value(nil).for(:role_approvers) }
        it { is_expected.to(validate_inclusion_of(:role_approvers).in_array(Gitlab::Access.values)) }
        ......
        ......@@ -30,13 +30,10 @@
        it { is_expected.to validate_uniqueness_of(:vulnerability_id) }
        it { is_expected.to validate_uniqueness_of(:uuid).case_insensitive }
        it { is_expected.to allow_value(true, false).for(:has_issues) }
        it { is_expected.to allow_value(true, false).for(:has_merge_request) }
        it { is_expected.not_to allow_value(nil).for(:has_issues) }
        it { is_expected.not_to allow_value(nil).for(:has_merge_request) }
        it { is_expected.to validate_inclusion_of(:has_issues).in_array([true, false]) }
        it { is_expected.to validate_inclusion_of(:has_merge_request).in_array([true, false]) }
        it { is_expected.to allow_value(true, false).for(:resolved_on_default_branch) }
        it { is_expected.not_to allow_value(nil).for(:resolved_on_default_branch) }
        it { is_expected.to validate_inclusion_of(:resolved_on_default_branch).in_array([true, false]) }
        end
        describe 'triggers' do
        ......
        ......@@ -7,8 +7,7 @@
        it { is_expected.to validate_length_of(:key).is_at_most(255) }
        it { is_expected.to validate_length_of(:value).is_at_most(255) }
        it { is_expected.not_to allow_value(nil).for(:active) }
        it { is_expected.to allow_value(true, false).for(:active) }
        it { is_expected.to validate_inclusion_of(:active).in_array([true, false]) }
        end
        describe '#to_hash' do
        ......
        ......@@ -69,8 +69,7 @@
        it { is_expected.to allow_value("dev.gitlab.com").for(:commit_email_hostname) }
        it { is_expected.not_to allow_value("@dev.gitlab").for(:commit_email_hostname) }
        it { is_expected.to allow_value(true, false).for(:container_expiration_policies_enable_historic_entries) }
        it { is_expected.not_to allow_value(nil).for(:container_expiration_policies_enable_historic_entries) }
        it { is_expected.to validate_inclusion_of(:container_expiration_policies_enable_historic_entries).in_array([true, false]) }
        it { is_expected.to allow_value("myemail@gitlab.com").for(:lets_encrypt_notification_email) }
        it { is_expected.to allow_value(nil).for(:lets_encrypt_notification_email) }
        ......@@ -113,7 +112,7 @@
        it { is_expected.to validate_numericality_of(:container_registry_cleanup_tags_service_max_list_size).only_integer.is_greater_than_or_equal_to(0) }
        it { is_expected.to validate_numericality_of(:container_registry_data_repair_detail_worker_max_concurrency).only_integer.is_greater_than_or_equal_to(0) }
        it { is_expected.to validate_numericality_of(:container_registry_expiration_policies_worker_capacity).only_integer.is_greater_than_or_equal_to(0) }
        it { is_expected.to allow_value(true, false).for(:container_registry_expiration_policies_caching) }
        it { is_expected.to validate_inclusion_of(:container_registry_expiration_policies_caching).in_array([true, false]) }
        it { is_expected.to validate_numericality_of(:container_registry_import_max_tags_count).only_integer.is_greater_than_or_equal_to(0) }
        it { is_expected.to validate_numericality_of(:container_registry_import_max_retries).only_integer.is_greater_than_or_equal_to(0) }
        ......@@ -149,8 +148,7 @@
        it { is_expected.to validate_numericality_of(:snippet_size_limit).only_integer.is_greater_than(0) }
        it { is_expected.to validate_numericality_of(:wiki_page_max_content_bytes).only_integer.is_greater_than_or_equal_to(1024) }
        it { is_expected.to allow_value(true, false).for(:wiki_asciidoc_allow_uri_includes) }
        it { is_expected.not_to allow_value(nil).for(:wiki_asciidoc_allow_uri_includes) }
        it { is_expected.to validate_inclusion_of(:wiki_asciidoc_allow_uri_includes).in_array([true, false]) }
        it { is_expected.to validate_presence_of(:max_artifacts_size) }
        it { is_expected.to validate_numericality_of(:max_artifacts_size).only_integer.is_greater_than(0) }
        it { is_expected.to validate_presence_of(:max_yaml_size_bytes) }
        ......@@ -162,11 +160,9 @@
        it { is_expected.to validate_presence_of(:max_terraform_state_size_bytes) }
        it { is_expected.to validate_numericality_of(:max_terraform_state_size_bytes).only_integer.is_greater_than_or_equal_to(0) }
        it { is_expected.to allow_value(true, false).for(:user_defaults_to_private_profile) }
        it { is_expected.not_to allow_value(nil).for(:user_defaults_to_private_profile) }
        it { is_expected.to validate_inclusion_of(:user_defaults_to_private_profile).in_array([true, false]) }
        it { is_expected.to allow_values([true, false]).for(:deny_all_requests_except_allowed) }
        it { is_expected.not_to allow_value(nil).for(:deny_all_requests_except_allowed) }
        it { is_expected.to validate_inclusion_of(:deny_all_requests_except_allowed).in_array([true, false]) }
        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)
        ......@@ -254,8 +250,7 @@ def many_usernames(num = 100)
        it { is_expected.to allow_value('http://example.com/').for(:public_runner_releases_url) }
        it { is_expected.not_to allow_value(nil).for(:public_runner_releases_url) }
        it { is_expected.to allow_value([true, false]).for(:update_runner_versions_enabled) }
        it { is_expected.not_to allow_value(nil).for(:update_runner_versions_enabled) }
        it { is_expected.to validate_inclusion_of(:update_runner_versions_enabled).in_array([true, false]) }
        it { is_expected.not_to allow_value(['']).for(:valid_runner_registrars) }
        it { is_expected.not_to allow_value(['OBVIOUSLY_WRONG']).for(:valid_runner_registrars) }
        ......@@ -268,21 +263,17 @@ def many_usernames(num = 100)
        it { is_expected.to allow_value(http).for(:jira_connect_proxy_url) }
        it { is_expected.to allow_value(https).for(:jira_connect_proxy_url) }
        it { is_expected.to allow_value(true, false).for(:bulk_import_enabled) }
        it { is_expected.not_to allow_value(nil).for(:bulk_import_enabled) }
        it { is_expected.to validate_inclusion_of(:bulk_import_enabled).in_array([true, false]) }
        it { is_expected.to allow_value(true, false).for(:allow_runner_registration_token) }
        it { is_expected.not_to allow_value(nil).for(:allow_runner_registration_token) }
        it { is_expected.to validate_inclusion_of(:allow_runner_registration_token).in_array([true, false]) }
        it { is_expected.to allow_value(true, false).for(:gitlab_dedicated_instance) }
        it { is_expected.not_to allow_value(nil).for(:gitlab_dedicated_instance) }
        it { is_expected.to validate_inclusion_of(:gitlab_dedicated_instance).in_array([true, false]) }
        it { is_expected.not_to allow_value(apdex_slo: '10').for(:prometheus_alert_db_indicators_settings) }
        it { is_expected.to allow_value(nil).for(:prometheus_alert_db_indicators_settings) }
        it { is_expected.to allow_value(valid_prometheus_alert_db_indicators_settings).for(:prometheus_alert_db_indicators_settings) }
        it { is_expected.to allow_value([true, false]).for(:silent_mode_enabled) }
        it { is_expected.not_to allow_value(nil).for(:silent_mode_enabled) }
        it { is_expected.to validate_inclusion_of(:silent_mode_enabled).in_array([true, false]) }
        it { is_expected.to allow_value(0).for(:ci_max_includes) }
        it { is_expected.to allow_value(200).for(:ci_max_includes) }
        ......@@ -298,16 +289,13 @@ def many_usernames(num = 100)
        it { is_expected.not_to allow_value(10.5).for(:ci_max_total_yaml_size_bytes) }
        it { is_expected.not_to allow_value(-1).for(:ci_max_total_yaml_size_bytes) }
        it { is_expected.to allow_value([true, false]).for(:remember_me_enabled) }
        it { is_expected.not_to allow_value(nil).for(:remember_me_enabled) }
        it { is_expected.to validate_inclusion_of(:remember_me_enabled).in_array([true, false]) }
        it { is_expected.to validate_numericality_of(:namespace_aggregation_schedule_lease_duration_in_seconds).only_integer.is_greater_than(0) }
        it { is_expected.to allow_values([true, false]).for(:instance_level_code_suggestions_enabled) }
        it { is_expected.not_to allow_value(nil).for(:instance_level_code_suggestions_enabled) }
        it { is_expected.to validate_inclusion_of(:instance_level_code_suggestions_enabled).in_array([true, false]) }
        it { is_expected.to allow_values([true, false]).for(:package_registry_allow_anyone_to_pull_option) }
        it { is_expected.not_to allow_value(nil).for(:package_registry_allow_anyone_to_pull_option) }
        it { is_expected.to validate_inclusion_of(:package_registry_allow_anyone_to_pull_option).in_array([true, false]) }
        context 'when deactivate_dormant_users is enabled' do
        before do
        ......
        ......@@ -11,8 +11,7 @@
        it { is_expected.to validate_presence_of(:project) }
        describe '#enabled' do
        it { is_expected.to allow_value(true, false).for(:enabled) }
        it { is_expected.not_to allow_value(nil).for(:enabled) }
        it { is_expected.to validate_inclusion_of(:enabled).in_array([true, false]) }
        end
        describe '#cadence' do
        ......
        ......@@ -11,8 +11,7 @@
        it { is_expected.to validate_presence_of(:group) }
        describe '#enabled' do
        it { is_expected.to allow_value(true, false).for(:enabled) }
        it { is_expected.not_to allow_value(nil).for(:enabled) }
        it { is_expected.to validate_inclusion_of(:enabled).in_array([true, false]) }
        end
        describe '#ttl' do
        ......
        ......@@ -13,8 +13,7 @@
        it { is_expected.to validate_presence_of :app_store_key_id }
        it { is_expected.to validate_presence_of :app_store_private_key }
        it { is_expected.to validate_presence_of :app_store_private_key_file_name }
        it { is_expected.to allow_value(true, false).for(:app_store_protected_refs) }
        it { is_expected.not_to allow_value(nil).for(:app_store_protected_refs) }
        it { is_expected.to validate_inclusion_of(:app_store_protected_refs).in_array([true, false]) }
        it { is_expected.to allow_value('aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee').for(:app_store_issuer_id) }
        it { is_expected.not_to allow_value('abcde').for(:app_store_issuer_id) }
        it { is_expected.to allow_value(File.read('spec/fixtures/ssl_key.pem')).for(:app_store_private_key) }
        ......
        ......@@ -20,8 +20,7 @@
        it { is_expected.to allow_value('a.a.a').for(:package_name) }
        it { is_expected.to allow_value('com.example').for(:package_name) }
        it { is_expected.not_to allow_value('com').for(:package_name) }
        it { is_expected.to allow_value(true, false).for(:google_play_protected_refs) }
        it { is_expected.not_to allow_value(nil).for(:google_play_protected_refs) }
        it { is_expected.to validate_inclusion_of(:google_play_protected_refs).in_array([true, false]) }
        it { is_expected.not_to allow_value('com.example.my app').for(:package_name) }
        it { is_expected.not_to allow_value('1com.example.myapp').for(:package_name) }
        it { is_expected.not_to allow_value('com.1example.myapp').for(:package_name) }
        ......
        ......@@ -69,8 +69,7 @@
        end
        describe 'validations' do
        it { is_expected.not_to allow_value(nil).for(:confidential) }
        it { is_expected.to allow_value(true, false).for(:confidential) }
        it { is_expected.to validate_inclusion_of(:confidential).in_array([true, false]) }
        end
        describe 'custom validations' do
        ......
        ......@@ -11,13 +11,9 @@
        it { is_expected.to validate_presence_of(:namespace) }
        describe '#maven_duplicates_allowed' do
        it { is_expected.to allow_value(true, false).for(:maven_duplicates_allowed) }
        it { is_expected.not_to allow_value(nil).for(:maven_duplicates_allowed) }
        it { is_expected.to allow_value(true, false).for(:generic_duplicates_allowed) }
        it { is_expected.not_to allow_value(nil).for(:generic_duplicates_allowed) }
        it { is_expected.to allow_value(true).for(:nuget_duplicates_allowed) }
        it { is_expected.to allow_value(false).for(:nuget_duplicates_allowed) }
        it { is_expected.not_to allow_value(nil).for(:nuget_duplicates_allowed) }
        it { is_expected.to validate_inclusion_of(:maven_duplicates_allowed).in_array([true, false]) }
        it { is_expected.to validate_inclusion_of(:generic_duplicates_allowed).in_array([true, false]) }
        it { is_expected.to validate_inclusion_of(:nuget_duplicates_allowed).in_array([true, false]) }
        end
        describe 'regex values' do
        ......
        ......@@ -26,8 +26,7 @@
        it { is_expected.to allow_value([]).for(:target_platforms) }
        it { is_expected.to validate_length_of(:issue_branch_template).is_at_most(255) }
        it { is_expected.not_to allow_value(nil).for(:suggested_reviewers_enabled) }
        it { is_expected.to allow_value(true, false).for(:suggested_reviewers_enabled) }
        it { is_expected.to validate_inclusion_of(:suggested_reviewers_enabled).in_array([true, false]) }
        it 'allows any combination of the allowed target platforms' do
        valid_target_platform_combinations.each do |target_platforms|
        ......
        ......@@ -49,8 +49,7 @@
        end
        describe 'pass_user_identities_to_ci_jwt' do
        it { is_expected.to allow_value(true, false).for(:pass_user_identities_to_ci_jwt) }
        it { is_expected.not_to allow_value(nil).for(:pass_user_identities_to_ci_jwt) }
        it { is_expected.to validate_inclusion_of(:pass_user_identities_to_ci_jwt).in_array([true, false]) }
        it { is_expected.not_to allow_value("").for(:pass_user_identities_to_ci_jwt) }
        end
        ......
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Finish editing this message first!
        Please register or to comment