Align EmailValidator to validate_email gem implementation
Summary
Renamed EmailValidator to DeviseEmailValidator to avoid 'email:' naming collision with ActiveModel::Validations::EmailValidator in 'validates' statement.
Make use of the options attribute of the parent class ActiveModel::EachValidator and add more options: regex.
Steps to reproduce
When adding the gem "openid-connect" to Gemfile, will pull the "validate_email" dependency that will overload the internal validator https://gitlab.com/gitlab-org/gitlab-ce/blob/master/app/validators/email_validator.rb with a different expectation for what a valid email means.
What is the current bug behavior?
When the new dependency is loaded the test for email https://gitlab.com/gitlab-org/gitlab-ce/blob/master/spec/support/shared_examples/email_format_shared_examples.rb#L14 and https://gitlab.com/gitlab-org/gitlab-ce/blob/master/spec/support/shared_examples/email_format_shared_examples.rb#L15 will fail.
What is the expected correct behavior?
Introduce new dependencies and all spec tests should run as expected.
Relevant logs and/or screenshots
expected #<ApplicationSetting id: 1, default_projects_limit: 42, signup_enabled: true, gravatar_enabled: true, sign_in_text: nil, created_at: "2019-02-06 14:55:35", updated_at: "2019-02-06 14:55:35", home_page_url: nil, default_branch_protection: 2, restricted_visibility_levels: [], version_check_enabled: true, max_attachment_size: 10, default_project_visibility: 0, default_snippet_visibility: 0, domain_whitelist: [], user_oauth_applications: true, after_sign_out_path: nil, session_expire_delay: 10080, import_sources: ["github", "bitbucket", "bitbucket_server", "gitlab", "google_code", "fogbugz", "git", "gitlab_project", "gitea", "manifest"], help_page_text: nil, admin_notification_email: "mailto:test@example.com", shared_runners_enabled: true, max_artifacts_size: 100, runners_registration_token: nil, max_pages_size: 100, require_two_factor_authentication: false, two_factor_grace_period: 48, metrics_enabled: false, metrics_host: "localhost", metrics_pool_size: 16, metrics_timeout: 10, metrics_method_call_threshold: 10, recaptcha_enabled: false, recaptcha_site_key: nil, recaptcha_private_key: nil, metrics_port: 8089, akismet_enabled: false, akismet_api_key: nil, metrics_sample_interval: 15, sentry_enabled: false, sentry_dsn: nil, email_author_in_body: false, default_group_visibility: 0, repository_checks_enabled: true, shared_runners_text: nil, metrics_packet_size: 1, disabled_oauth_sign_in_sources: [], health_check_access_token: "LiGnxELy1QjaQrETUQm6", send_user_confirmation_email: false, container_registry_token_expire_delay: 5, after_sign_up_text: nil, user_default_external: false, repository_storages: ["default"], enabled_git_access_protocol: nil, domain_blacklist_enabled: false, domain_blacklist: [], usage_ping_enabled: true, sign_in_text_html: "", help_page_text_html: "", shared_runners_text_html: "", after_sign_up_text_html: "", rsa_key_restriction: 0, dsa_key_restriction: 0, ecdsa_key_restriction: 0, ed25519_key_restriction: 0, housekeeping_enabled: true, housekeeping_bitmaps_enabled: true, housekeeping_incremental_repack_period: 10, housekeeping_full_repack_period: 50, housekeeping_gc_period: 200, html_emails_enabled: true, plantuml_url: nil, plantuml_enabled: false, terminal_max_session_time: 0, unique_ips_limit_per_user: 10, unique_ips_limit_time_window: 3600, unique_ips_limit_enabled: false, default_artifacts_expire_in: "30 days", uuid: "9ba4e423-f939-4eb3-bd79-64bfc866ec5e", polling_interval_multiplier: 0.1e1, cached_markdown_version: 14, clientside_sentry_enabled: false, clientside_sentry_dsn: nil, prometheus_metrics_enabled: true, help_page_hide_commercial_content: false, help_page_support_url: nil, performance_bar_allowed_group_id: nil, hashed_storage_enabled: false, project_export_enabled: true, auto_devops_enabled: true, throttle_unauthenticated_enabled: false, throttle_unauthenticated_requests_per_period: 3600, throttle_unauthenticated_period_in_seconds: 3600, throttle_authenticated_api_enabled: false, throttle_authenticated_api_requests_per_period: 7200, throttle_authenticated_api_period_in_seconds: 3600, throttle_authenticated_web_enabled: false, throttle_authenticated_web_requests_per_period: 7200, throttle_authenticated_web_period_in_seconds: 3600, password_authentication_enabled_for_web: true, password_authentication_enabled_for_git: true, gitaly_timeout_default: 55, gitaly_timeout_medium: 30, gitaly_timeout_fast: 10, authorized_keys_enabled: true, auto_devops_domain: nil, pages_domain_verification_enabled: true, user_default_internal_regex: nil, allow_local_requests_from_hooks_and_services: false, enforce_terms: false, mirror_available: true, hide_third_party_offers: false, instance_statistics_visibility_private: false, web_ide_clientside_preview_enabled: false, user_show_add_ssh_key_message: true, usage_stats_set_by_user_id: nil, receive_max_input_size: nil, diff_max_patch_bytes: 102400, archive_builds_in_seconds: nil, commit_email_hostname: "users.noreply.localhost", protected_ci_variables: false, runners_registration_token_encrypted: "6pDjAvxjghxDtNceMHB/jec+uEdfnKJbA4mcO/Tb3Q7oAM45"> to be valid, but got errors: Admin notification email is not a valid email address
0) ApplicationSetting validations behaves like an object with email-formated attributes specifically its :admin_notification_email attribute with a value of 'mailto:test@example.com' is valid
Failure/Error: expect(subject).to be_valid
expected #<ApplicationSetting id: 1, default_projects_limit: 42, signup_enabled: true, gravatar_enabled: true, sign_in_text: nil, created_at: "2019-02-06 14:55:35", updated_at: "2019-02-06 14:55:35", home_page_url: nil, default_branch_protection: 2, restricted_visibility_levels: [], version_check_enabled: true, max_attachment_size: 10, default_project_visibility: 0, default_snippet_visibility: 0, domain_whitelist: [], user_oauth_applications: true, after_sign_out_path: nil, session_expire_delay: 10080, import_sources: ["github", "bitbucket", "bitbucket_server", "gitlab", "google_code", "fogbugz", "git", "gitlab_project", "gitea", "manifest"], help_page_text: nil, admin_notification_email: "mailto:test@example.com", shared_runners_enabled: true, max_artifacts_size: 100, runners_registration_token: nil, max_pages_size: 100, require_two_factor_authentication: false, two_factor_grace_period: 48, metrics_enabled: false, metrics_host: "localhost", metrics_pool_size: 16, metrics_timeout: 10, metrics_method_call_threshold: 10, recaptcha_enabled: false, recaptcha_site_key: nil, recaptcha_private_key: nil, metrics_port: 8089, akismet_enabled: false, akismet_api_key: nil, metrics_sample_interval: 15, sentry_enabled: false, sentry_dsn: nil, email_author_in_body: false, default_group_visibility: 0, repository_checks_enabled: true, shared_runners_text: nil, metrics_packet_size: 1, disabled_oauth_sign_in_sources: [], health_check_access_token: "LiGnxELy1QjaQrETUQm6", send_user_confirmation_email: false, container_registry_token_expire_delay: 5, after_sign_up_text: nil, user_default_external: false, repository_storages: ["default"], enabled_git_access_protocol: nil, domain_blacklist_enabled: false, domain_blacklist: [], usage_ping_enabled: true, sign_in_text_html: "", help_page_text_html: "", shared_runners_text_html: "", after_sign_up_text_html: "", rsa_key_restriction: 0, dsa_key_restriction: 0, ecdsa_key_restriction: 0, ed25519_key_restriction: 0, housekeeping_enabled: true, housekeeping_bitmaps_enabled: true, housekeeping_incremental_repack_period: 10, housekeeping_full_repack_period: 50, housekeeping_gc_period: 200, html_emails_enabled: true, plantuml_url: nil, plantuml_enabled: false, terminal_max_session_time: 0, unique_ips_limit_per_user: 10, unique_ips_limit_time_window: 3600, unique_ips_limit_enabled: false, default_artifacts_expire_in: "30 days", uuid: "9ba4e423-f939-4eb3-bd79-64bfc866ec5e", polling_interval_multiplier: 0.1e1, cached_markdown_version: 14, clientside_sentry_enabled: false, clientside_sentry_dsn: nil, prometheus_metrics_enabled: true, help_page_hide_commercial_content: false, help_page_support_url: nil, performance_bar_allowed_group_id: nil, hashed_storage_enabled: false, project_export_enabled: true, auto_devops_enabled: true, throttle_unauthenticated_enabled: false, throttle_unauthenticated_requests_per_period: 3600, throttle_unauthenticated_period_in_seconds: 3600, throttle_authenticated_api_enabled: false, throttle_authenticated_api_requests_per_period: 7200, throttle_authenticated_api_period_in_seconds: 3600, throttle_authenticated_web_enabled: false, throttle_authenticated_web_requests_per_period: 7200, throttle_authenticated_web_period_in_seconds: 3600, password_authentication_enabled_for_web: true, password_authentication_enabled_for_git: true, gitaly_timeout_default: 55, gitaly_timeout_medium: 30, gitaly_timeout_fast: 10, authorized_keys_enabled: true, auto_devops_domain: nil, pages_domain_verification_enabled: true, user_default_internal_regex: nil, allow_local_requests_from_hooks_and_services: false, enforce_terms: false, mirror_available: true, hide_third_party_offers: false, instance_statistics_visibility_private: false, web_ide_clientside_preview_enabled: false, user_show_add_ssh_key_message: true, usage_stats_set_by_user_id: nil, receive_max_input_size: nil, diff_max_patch_bytes: 102400, archive_builds_in_seconds: nil, commit_email_hostname: "users.noreply.localhost", protected_ci_variables: false, runners_registration_token_encrypted: "6pDjAvxjghxDtNceMHB/jec+uEdfnKJbA4mcO/Tb3Q7oAM45"> to be valid, but got errors: Admin notification email is not a valid email address
Shared Example Group: "an object with email-formated attributes" called from ./spec/models/application_setting_spec.rb:100
# ./spec/support/shared_examples/email_format_shared_examples.rb:23:in `block (6 levels) in <top (required)>'
# /home/default/.gem/gems/rspec-retry-0.4.5/lib/rspec/retry.rb:98:in `block in run'
# /home/default/.gem/gems/rspec-retry-0.4.5/lib/rspec/retry.rb:88:in `loop'
# /home/default/.gem/gems/rspec-retry-0.4.5/lib/rspec/retry.rb:88:in `run'
# /home/default/.gem/gems/rspec-retry-0.4.5/lib/rspec_ext/rspec_ext.rb:12:in `run_with_retry'
# /home/default/.gem/gems/rspec-retry-0.4.5/lib/rspec/retry.rb:22:in `block (2 levels) in setup'
expected #<ApplicationSetting id: 1, default_projects_limit: 42, signup_enabled: true, gravatar_enabled: true, sign_in_text: nil, created_at: "2019-02-06 14:55:35", updated_at: "2019-02-06 14:55:35", home_page_url: nil, default_branch_protection: 2, restricted_visibility_levels: [], version_check_enabled: true, max_attachment_size: 10, default_project_visibility: 0, default_snippet_visibility: 0, domain_whitelist: [], user_oauth_applications: true, after_sign_out_path: nil, session_expire_delay: 10080, import_sources: ["github", "bitbucket", "bitbucket_server", "gitlab", "google_code", "fogbugz", "git", "gitlab_project", "gitea", "manifest"], help_page_text: nil, admin_notification_email: "lol!'+=?><\#$%^&*()@gmail.com", shared_runners_enabled: true, max_artifacts_size: 100, runners_registration_token: nil, max_pages_size: 100, require_two_factor_authentication: false, two_factor_grace_period: 48, metrics_enabled: false, metrics_host: "localhost", metrics_pool_size: 16, metrics_timeout: 10, metrics_method_call_threshold: 10, recaptcha_enabled: false, recaptcha_site_key: nil, recaptcha_private_key: nil, metrics_port: 8089, akismet_enabled: false, akismet_api_key: nil, metrics_sample_interval: 15, sentry_enabled: false, sentry_dsn: nil, email_author_in_body: false, default_group_visibility: 0, repository_checks_enabled: true, shared_runners_text: nil, metrics_packet_size: 1, disabled_oauth_sign_in_sources: [], health_check_access_token: "1pmcZEyeu3XB7WoGJPJ2", send_user_confirmation_email: false, container_registry_token_expire_delay: 5, after_sign_up_text: nil, user_default_external: false, repository_storages: ["default"], enabled_git_access_protocol: nil, domain_blacklist_enabled: false, domain_blacklist: [], usage_ping_enabled: true, sign_in_text_html: "", help_page_text_html: "", shared_runners_text_html: "", after_sign_up_text_html: "", rsa_key_restriction: 0, dsa_key_restriction: 0, ecdsa_key_restriction: 0, ed25519_key_restriction: 0, housekeeping_enabled: true, housekeeping_bitmaps_enabled: true, housekeeping_incremental_repack_period: 10, housekeeping_full_repack_period: 50, housekeeping_gc_period: 200, html_emails_enabled: true, plantuml_url: nil, plantuml_enabled: false, terminal_max_session_time: 0, unique_ips_limit_per_user: 10, unique_ips_limit_time_window: 3600, unique_ips_limit_enabled: false, default_artifacts_expire_in: "30 days", uuid: "c3c917c8-b190-4007-a69b-eff899420a7d", polling_interval_multiplier: 0.1e1, cached_markdown_version: 14, clientside_sentry_enabled: false, clientside_sentry_dsn: nil, prometheus_metrics_enabled: true, help_page_hide_commercial_content: false, help_page_support_url: nil, performance_bar_allowed_group_id: nil, hashed_storage_enabled: false, project_export_enabled: true, auto_devops_enabled: true, throttle_unauthenticated_enabled: false, throttle_unauthenticated_requests_per_period: 3600, throttle_unauthenticated_period_in_seconds: 3600, throttle_authenticated_api_enabled: false, throttle_authenticated_api_requests_per_period: 7200, throttle_authenticated_api_period_in_seconds: 3600, throttle_authenticated_web_enabled: false, throttle_authenticated_web_requests_per_period: 7200, throttle_authenticated_web_period_in_seconds: 3600, password_authentication_enabled_for_web: true, password_authentication_enabled_for_git: true, gitaly_timeout_default: 55, gitaly_timeout_medium: 30, gitaly_timeout_fast: 10, authorized_keys_enabled: true, auto_devops_domain: nil, pages_domain_verification_enabled: true, user_default_internal_regex: nil, allow_local_requests_from_hooks_and_services: false, enforce_terms: false, mirror_available: true, hide_third_party_offers: false, instance_statistics_visibility_private: false, web_ide_clientside_preview_enabled: false, user_show_add_ssh_key_message: true, usage_stats_set_by_user_id: nil, receive_max_input_size: nil, diff_max_patch_bytes: 102400, archive_builds_in_seconds: nil, commit_email_hostname: "users.noreply.localhost", protected_ci_variables: false, runners_registration_token_encrypted: "7IDdFe5TrSNmv8gpB1dVj88fnF445AxL+qwh1jEvaQlExRcy"> to be valid, but got errors: Admin notification email is not a valid email address
0) ApplicationSetting validations behaves like an object with email-formated attributes specifically its :admin_notification_email attribute with a value of 'lol!'+=?><#$%^&*()@gmail.com' is valid
Failure/Error: expect(subject).to be_valid
expected #<ApplicationSetting id: 1, default_projects_limit: 42, signup_enabled: true, gravatar_enabled: true, sign_in_text: nil, created_at: "2019-02-06 14:55:35", updated_at: "2019-02-06 14:55:35", home_page_url: nil, default_branch_protection: 2, restricted_visibility_levels: [], version_check_enabled: true, max_attachment_size: 10, default_project_visibility: 0, default_snippet_visibility: 0, domain_whitelist: [], user_oauth_applications: true, after_sign_out_path: nil, session_expire_delay: 10080, import_sources: ["github", "bitbucket", "bitbucket_server", "gitlab", "google_code", "fogbugz", "git", "gitlab_project", "gitea", "manifest"], help_page_text: nil, admin_notification_email: "lol!'+=?><\#$%^&*()@gmail.com", shared_runners_enabled: true, max_artifacts_size: 100, runners_registration_token: nil, max_pages_size: 100, require_two_factor_authentication: false, two_factor_grace_period: 48, metrics_enabled: false, metrics_host: "localhost", metrics_pool_size: 16, metrics_timeout: 10, metrics_method_call_threshold: 10, recaptcha_enabled: false, recaptcha_site_key: nil, recaptcha_private_key: nil, metrics_port: 8089, akismet_enabled: false, akismet_api_key: nil, metrics_sample_interval: 15, sentry_enabled: false, sentry_dsn: nil, email_author_in_body: false, default_group_visibility: 0, repository_checks_enabled: true, shared_runners_text: nil, metrics_packet_size: 1, disabled_oauth_sign_in_sources: [], health_check_access_token: "1pmcZEyeu3XB7WoGJPJ2", send_user_confirmation_email: false, container_registry_token_expire_delay: 5, after_sign_up_text: nil, user_default_external: false, repository_storages: ["default"], enabled_git_access_protocol: nil, domain_blacklist_enabled: false, domain_blacklist: [], usage_ping_enabled: true, sign_in_text_html: "", help_page_text_html: "", shared_runners_text_html: "", after_sign_up_text_html: "", rsa_key_restriction: 0, dsa_key_restriction: 0, ecdsa_key_restriction: 0, ed25519_key_restriction: 0, housekeeping_enabled: true, housekeeping_bitmaps_enabled: true, housekeeping_incremental_repack_period: 10, housekeeping_full_repack_period: 50, housekeeping_gc_period: 200, html_emails_enabled: true, plantuml_url: nil, plantuml_enabled: false, terminal_max_session_time: 0, unique_ips_limit_per_user: 10, unique_ips_limit_time_window: 3600, unique_ips_limit_enabled: false, default_artifacts_expire_in: "30 days", uuid: "c3c917c8-b190-4007-a69b-eff899420a7d", polling_interval_multiplier: 0.1e1, cached_markdown_version: 14, clientside_sentry_enabled: false, clientside_sentry_dsn: nil, prometheus_metrics_enabled: true, help_page_hide_commercial_content: false, help_page_support_url: nil, performance_bar_allowed_group_id: nil, hashed_storage_enabled: false, project_export_enabled: true, auto_devops_enabled: true, throttle_unauthenticated_enabled: false, throttle_unauthenticated_requests_per_period: 3600, throttle_unauthenticated_period_in_seconds: 3600, throttle_authenticated_api_enabled: false, throttle_authenticated_api_requests_per_period: 7200, throttle_authenticated_api_period_in_seconds: 3600, throttle_authenticated_web_enabled: false, throttle_authenticated_web_requests_per_period: 7200, throttle_authenticated_web_period_in_seconds: 3600, password_authentication_enabled_for_web: true, password_authentication_enabled_for_git: true, gitaly_timeout_default: 55, gitaly_timeout_medium: 30, gitaly_timeout_fast: 10, authorized_keys_enabled: true, auto_devops_domain: nil, pages_domain_verification_enabled: true, user_default_internal_regex: nil, allow_local_requests_from_hooks_and_services: false, enforce_terms: false, mirror_available: true, hide_third_party_offers: false, instance_statistics_visibility_private: false, web_ide_clientside_preview_enabled: false, user_show_add_ssh_key_message: true, usage_stats_set_by_user_id: nil, receive_max_input_size: nil, diff_max_patch_bytes: 102400, archive_builds_in_seconds: nil, commit_email_hostname: "users.noreply.localhost", protected_ci_variables: false, runners_registration_token_encrypted: "7IDdFe5TrSNmv8gpB1dVj88fnF445AxL+qwh1jEvaQlExRcy"> to be valid, but got errors: Admin notification email is not a valid email address
Shared Example Group: "an object with email-formated attributes" called from ./spec/models/application_setting_spec.rb:100
# ./spec/support/shared_examples/email_format_shared_examples.rb:23:in `block (6 levels) in <top (required)>'
# /home/default/.gem/gems/rspec-retry-0.4.5/lib/rspec/retry.rb:98:in `block in run'
# /home/default/.gem/gems/rspec-retry-0.4.5/lib/rspec/retry.rb:88:in `loop'
# /home/default/.gem/gems/rspec-retry-0.4.5/lib/rspec/retry.rb:88:in `run'
# /home/default/.gem/gems/rspec-retry-0.4.5/lib/rspec_ext/rspec_ext.rb:12:in `run_with_retry'
# /home/default/.gem/gems/rspec-retry-0.4.5/lib/rspec/retry.rb:22:in `block (2 levels) in setup'