Sha256: 11f858421ac9124eaf01be6db036f82ab806a9972412777cc48e0a6f57d13ec8

Contents?: true

Size: 1.15 KB

Versions: 43

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

require 'rails_helper'
require 'spree/core/validators/email'

RSpec.describe Spree::EmailValidator do
  class Tester
    include ActiveModel::Validations
    attr_accessor :email_address
    validates :email_address, 'spree/email' => true
  end

  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'
  ]
  }
  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'
  ]
  }

  it 'validates valid email addresses' do
    tester = Tester.new
    valid_emails.each do |email|
      tester.email_address = email
      expect(tester.valid?).to be true
    end
  end

  it 'validates invalid email addresses' do
    tester = Tester.new
    invalid_emails.each do |email|
      tester.email_address = email
      expect(tester.valid?).to be false
    end
  end
end

Version data entries

43 entries across 43 versions & 2 rubygems

Version Path
solidus_core-2.8.1 spec/lib/spree/core/validators/email_spec.rb
solidus_core-2.6.3 spec/lib/spree/core/validators/email_spec.rb
solidus_core-2.8.0 spec/lib/spree/core/validators/email_spec.rb
solidus_core-2.7.1 spec/lib/spree/core/validators/email_spec.rb
solidus_core-2.6.2 spec/lib/spree/core/validators/email_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.14 spec/lib/spree/core/validators/email_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.13 spec/lib/spree/core/validators/email_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.12 spec/lib/spree/core/validators/email_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.11 spec/lib/spree/core/validators/email_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.10 spec/lib/spree/core/validators/email_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.9 spec/lib/spree/core/validators/email_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.8 spec/lib/spree/core/validators/email_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.7 spec/lib/spree/core/validators/email_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.6 spec/lib/spree/core/validators/email_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.5 spec/lib/spree/core/validators/email_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.4 spec/lib/spree/core/validators/email_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.3 spec/lib/spree/core/validators/email_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.1 spec/lib/spree/core/validators/email_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.0 spec/lib/spree/core/validators/email_spec.rb
solidus_core-2.7.0 spec/lib/spree/core/validators/email_spec.rb