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.6.1 spec/lib/spree/core/validators/email_spec.rb
solidus_core-2.6.0 spec/lib/spree/core/validators/email_spec.rb
solidus_core-2.6.0.rc1 spec/lib/spree/core/validators/email_spec.rb