From cae386ce380e2272ddd40429575816ea47914360 Mon Sep 17 00:00:00 2001 From: JDutil Date: Wed, 23 Oct 2019 15:23:57 -0600 Subject: [PATCH 1/2] Remove Deprecated EmailValidator The email validator was deprecated Mar 15th 2018 almost 18 months ago as part of: https://github.com/solidusio/solidus/commit/6d8fd3cef4819801eed5574c9bf7b5ec0a0e305c The deprecation warning was part of v2.6.0rc1, and remains to this day in v2.10.0.beta1 I think it's time to remove it altogether. It's been 4 minor version upgrades now. --- core/lib/spree/core/validators/email.rb | 7 ---- .../lib/spree/core/validators/email_spec.rb | 36 +++++++++---------- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/core/lib/spree/core/validators/email.rb b/core/lib/spree/core/validators/email.rb index 6e73d02bf24..831f96b856c 100644 --- a/core/lib/spree/core/validators/email.rb +++ b/core/lib/spree/core/validators/email.rb @@ -21,10 +21,3 @@ def validate_each(record, attribute, value) end end end - -# @private -EmailValidator = ActiveSupport::Deprecation::DeprecatedConstantProxy.new( - 'EmailValidator', - 'Spree::EmailValidator', - message: "EmailValidator is deprecated! Use Spree::EmailValidator instead.\nChange `validates :email, email: true` to `validates :email, 'spree/email' => true`\n" -) diff --git a/core/spec/lib/spree/core/validators/email_spec.rb b/core/spec/lib/spree/core/validators/email_spec.rb index db2730cced6..7ab4843a362 100644 --- a/core/spec/lib/spree/core/validators/email_spec.rb +++ b/core/spec/lib/spree/core/validators/email_spec.rb @@ -12,27 +12,27 @@ class Tester let(:valid_emails) { [ - 'valid@email.com', - 'valid@email.com.uk', - 'e@email.com', - 'valid+email@email.com', - 'valid-email@email.com', - 'valid_email@email.com', - 'valid.email@email.com' - ] + 'valid@email.com', + 'valid@email.com.uk', + 'e@email.com', + 'valid+email@email.com', + 'valid-email@email.com', + 'valid_email@email.com', + 'valid.email@email.com' + ] } let(:invalid_emails) { [ - 'invalid email@email.com', - '.invalid.email@email.com', - 'invalid.email.@email.com', - '@email.com', - '.@email.com', - 'invalidemailemail.com', - '@invalid.email@email.com', - 'invalid@email@email.com', - 'invalid.email@@email.com' - ] + 'invalid email@email.com', + '.invalid.email@email.com', + 'invalid.email.@email.com', + '@email.com', + '.@email.com', + 'invalidemailemail.com', + '@invalid.email@email.com', + 'invalid@email@email.com', + 'invalid.email@@email.com' + ] } it 'validates valid email addresses' do From bea27dc07518b37b516d5f1dc9425d81ee724d21 Mon Sep 17 00:00:00 2001 From: JDutil Date: Sat, 26 Oct 2019 12:30:26 -0600 Subject: [PATCH 2/2] Fix Performance/RegexpMatch Rubocop warning Rubocop warns to use `match?` instead of `=~` for performance. --- core/lib/spree/core/validators/email.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/lib/spree/core/validators/email.rb b/core/lib/spree/core/validators/email.rb index 831f96b856c..a519aabb52a 100644 --- a/core/lib/spree/core/validators/email.rb +++ b/core/lib/spree/core/validators/email.rb @@ -15,7 +15,7 @@ class EmailValidator < ActiveModel::EachValidator EMAIL_REGEXP = /\A([^@\.]|[^@\.]([^@\s]*)[^@\.])@([^@\s]+\.)+[^@\s]+\z/ def validate_each(record, attribute, value) - unless value =~ EMAIL_REGEXP + unless EMAIL_REGEXP.match? value record.errors.add(attribute, :invalid, { value: value }.merge!(options)) end end