validate_as_email 2.1.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c4626da4baee6844bc5862c747e58d60eccc7cd
4
- data.tar.gz: 5660997cc54f2bbfc1b73f084c110064ed0f4db6
3
+ metadata.gz: 28ec894f592a434dcab3f7a29822fc68184248ca
4
+ data.tar.gz: 652bca29a770d9b1e52236f103cfb7ca3ebf32c9
5
5
  SHA512:
6
- metadata.gz: 2324c402331da683d64a6b465650530ada5b99c754694c28a7c2a675b5ac605c371c499308de25313ad54a43849d0b223955bb62511895a6023f028be207015a
7
- data.tar.gz: 35e7e558ce5b1dd6d3a023f97188890635010ae1f67636704e962c0fbe1271c6434796a1f238d32eb3c233b224ec8c3fd690b2390cb2461cdda87d8b9ed00359
6
+ metadata.gz: 03243e0cbdf5f6d4782943f66dab6fd65d00db62f839cad14c2f4a3f04e76795351115ce7dc3ccded97bfa5b70fb9fb956ae6b94ef448d7077351608b9a2ad87
7
+ data.tar.gz: 1713e9ae94e98dc9f9516e76e53243339cef1ee618c517288ae0cb098ea246e485dd91583ae608cbd8c161e87e03f81b6530cb87466c185332d7c29dba2cded2
data/README.md CHANGED
@@ -1,6 +1,4 @@
1
- # Validate as Email
2
-
3
- [![Build Status](https://travis-ci.org/listora/validate_as_email.png?branch=master)](https://travis-ci.org/listora/validate_as_email)
1
+ # Validate as Email [![Circle CI](https://circleci.com/gh/jcf/validate_as_email.svg?style=svg)](https://circleci.com/gh/jcf/validate_as_email)
4
2
 
5
3
  Validation of email addresses via the excellent Mail gem that is
6
4
  available in all Rails 3 and 4 applications.
@@ -4,19 +4,26 @@ require 'mail'
4
4
  module ActiveModel
5
5
  module Validations
6
6
  class EmailValidator < EachValidator
7
- attr_reader :record, :attribute, :value, :email, :tree
7
+ attr_reader :record, :attribute, :value, :email
8
8
 
9
9
  def validate_each(record, attribute, value)
10
10
  @record, @attribute, @value = record, attribute, value
11
11
 
12
12
  @email = Mail::Address.new(value)
13
- @tree = email.__send__(:tree)
14
13
 
15
14
  add_error unless valid?
16
15
  rescue Mail::Field::ParseError
17
16
  add_error
18
17
  end
19
18
 
19
+ def domain_parts
20
+ @domain_parts ||= if email.domain
21
+ email.domain.split('.')
22
+ else
23
+ []
24
+ end
25
+ end
26
+
20
27
  private
21
28
 
22
29
  def valid?
@@ -28,7 +35,7 @@ module ActiveModel
28
35
  end
29
36
 
30
37
  def domain_has_more_than_one_atom?
31
- tree.domain.dot_atom_text.elements.length > 1
38
+ domain_parts.length > 1
32
39
  end
33
40
 
34
41
  def add_error
@@ -1,3 +1,3 @@
1
1
  module ValidateAsEmail
2
- VERSION = '2.1.0'
2
+ VERSION = '3.0.0'
3
3
  end
@@ -1,75 +1,57 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ActiveModel::Validations::EmailValidator do
4
- let(:person) { Person.new(email: 'invalid') }
5
-
6
- let(:options) { {attributes: [:email]} }
7
-
8
- def build_validator(options = {})
9
- ActiveModel::Validations::EmailValidator.new(
10
- options.merge(attributes: [:email])
11
- )
12
- end
13
-
14
- subject(:validator) { build_validator }
15
-
16
4
  describe '#validate' do
17
- context 'with a valid email address' do
18
- before do
19
- person.email = 'james@logi.cl'
20
- end
21
-
22
- it 'does not add errors' do
23
- validator.validate(person)
24
- person.errors.to_a.should == []
25
- end
26
- end
27
-
28
- context 'with nil allowed' do
29
- subject(:validator) do
30
- build_validator(allow_nil: true)
31
- end
32
-
33
- before do
34
- person.email = nil
35
- end
36
-
37
- it 'skips adding errors is email is nil' do
38
- validator.validate(person)
39
- person.errors.to_a.should == []
40
- end
41
- end
42
-
43
- context 'with blank is allowed' do
44
- subject(:validator) do
45
- build_validator(allow_blank: true)
46
- end
47
-
48
- before do
49
- person.email = ' '
50
- end
51
-
52
- it 'skips adding errors is email is nil' do
53
- validator.validate(person)
54
- person.errors.to_a.should == []
55
- end
56
- end
57
-
58
- context 'with no message provided' do
59
- it 'adds a symbol to errors for I18n lookup' do
60
- validator.validate(person)
61
- person.errors.to_a.should == ['Email is invalid']
62
- end
63
- end
64
-
65
- context 'with a specific error message provided' do
66
- subject(:validator) do
67
- build_validator(message: 'is kinda odd looking')
68
- end
69
-
70
- it 'uses the message you specify' do
71
- validator.validate(person)
72
- person.errors.to_a.should == ['Email is kinda odd looking']
5
+ [
6
+ {
7
+ desc: 'with a valid email address',
8
+ validator: {},
9
+ people: [
10
+ {email: 'a@b.c'},
11
+ {email: 'a+x@b.c'},
12
+ {email: 'a@192.168.0.1'},
13
+ {email: '1@1.com'}
14
+ ],
15
+ errors: []
16
+ },
17
+ {
18
+ desc: 'with nil allowed',
19
+ validator: {allow_nil: true},
20
+ people: [ {email: nil} ],
21
+ errors: []
22
+ },
23
+ {
24
+ desc: 'with blank allowed',
25
+ validator: {allow_blank: true},
26
+ people: [ {email: ' '}, {email: "\t\n"} ],
27
+ errors: []
28
+ },
29
+ {
30
+ desc: 'with no message provided',
31
+ validator: {},
32
+ people: [ {email: 'invalid'}, {email: ' '} ],
33
+ errors: ['Email is invalid']
34
+ },
35
+ {
36
+ desc: 'with a custom error message',
37
+ validator: {message: 'is kinda odd looking'},
38
+ people: [ {email: 'invalid'}, {email: ' '} ],
39
+ errors: ['Email is kinda odd looking']
40
+ }
41
+ ].each do |data|
42
+ data[:people].each do |person_attributes|
43
+ context data do
44
+ let(:person) { Person.new(person_attributes) }
45
+
46
+ let(:validator) do
47
+ ActiveModel::Validations::EmailValidator.new(
48
+ data[:validator].merge(attributes: [:email])
49
+ )
50
+ end
51
+
52
+ before { validator.validate(person) }
53
+ it { expect(person.errors.to_a).to eq(data[:errors]) }
54
+ end
73
55
  end
74
56
  end
75
57
  end
metadata CHANGED
@@ -1,50 +1,44 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validate_as_email
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Conroy-Finn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-30 00:00:00.000000000 Z
11
+ date: 2016-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3'
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '4.1'
19
+ version: '0'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - ">"
28
- - !ruby/object:Gem::Version
29
- version: '3'
30
- - - "<"
24
+ - - ">="
31
25
  - !ruby/object:Gem::Version
32
- version: '4.1'
26
+ version: '0'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: mail
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
- - - "~>"
31
+ - - ">="
38
32
  - !ruby/object:Gem::Version
39
- version: '2.5'
33
+ version: '0'
40
34
  type: :runtime
41
35
  prerelease: false
42
36
  version_requirements: !ruby/object:Gem::Requirement
43
37
  requirements:
44
- - - "~>"
38
+ - - ">="
45
39
  - !ruby/object:Gem::Version
46
- version: '2.5'
47
- description: The ultimate Rails 3 email validator
40
+ version: '0'
41
+ description: The ultimate email validator
48
42
  email:
49
43
  - james@logi.cl
50
44
  executables: []
@@ -60,7 +54,7 @@ files:
60
54
  - spec/active_model/validations/email_validator_spec.rb
61
55
  - spec/spec_helper.rb
62
56
  - spec/support/model.rb
63
- homepage: https://github.com/evently/mail_validator
57
+ homepage: https://github.com/jcf/validate_as_email
64
58
  licenses: []
65
59
  metadata: {}
66
60
  post_install_message:
@@ -79,10 +73,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
73
  version: '0'
80
74
  requirements: []
81
75
  rubyforge_project:
82
- rubygems_version: 2.2.0
76
+ rubygems_version: 2.4.5.1
83
77
  signing_key:
84
78
  specification_version: 4
85
- summary: The ultimate Rails 3 email validator. Powered by the Mail gem.
79
+ summary: The ultimate email validator. Powered by the Mail gem.
86
80
  test_files:
87
81
  - spec/active_model/validations/email_validator_spec.rb
88
82
  - spec/spec_helper.rb