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.9.6 spec/lib/spree/core/validators/email_spec.rb
solidus_core-2.8.6 spec/lib/spree/core/validators/email_spec.rb
solidus_core-2.9.5 spec/lib/spree/core/validators/email_spec.rb
solidus_core-2.9.4 spec/lib/spree/core/validators/email_spec.rb
solidus_core-2.6.6 spec/lib/spree/core/validators/email_spec.rb
solidus_core-2.7.4 spec/lib/spree/core/validators/email_spec.rb
solidus_core-2.8.5 spec/lib/spree/core/validators/email_spec.rb
solidus_core-2.9.3 spec/lib/spree/core/validators/email_spec.rb
solidus_core-2.9.2 spec/lib/spree/core/validators/email_spec.rb
solidus_core-2.10.0.beta1 spec/lib/spree/core/validators/email_spec.rb
solidus_core-2.7.3 spec/lib/spree/core/validators/email_spec.rb
solidus_core-2.6.5 spec/lib/spree/core/validators/email_spec.rb
solidus_core-2.9.1 spec/lib/spree/core/validators/email_spec.rb
solidus_core-2.9.0 spec/lib/spree/core/validators/email_spec.rb
solidus_core-2.9.0.rc.1 spec/lib/spree/core/validators/email_spec.rb
solidus_core-2.8.4 spec/lib/spree/core/validators/email_spec.rb
solidus_core-2.8.3 spec/lib/spree/core/validators/email_spec.rb
solidus_core-2.7.2 spec/lib/spree/core/validators/email_spec.rb
solidus_core-2.6.4 spec/lib/spree/core/validators/email_spec.rb
solidus_core-2.8.2 spec/lib/spree/core/validators/email_spec.rb