email_validator 1.1.0 → 1.2.1
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.
- data/.gitignore +21 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +32 -0
- data/README.rdoc +1 -0
- data/Rakefile +9 -42
- data/email_validator.gemspec +6 -37
- data/lib/email_validator.rb +4 -2
- data/spec/email_validator_spec.rb +100 -0
- data/spec/spec_helper.rb +20 -0
- metadata +13 -12
- data/VERSION +0 -1
- data/init.rb +0 -1
- data/test/helper.rb +0 -23
- data/test/test_email_validator.rb +0 -51
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
email_validator (1.2.1)
|
5
|
+
activemodel
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (3.0.9)
|
11
|
+
activesupport (= 3.0.9)
|
12
|
+
builder (~> 2.1.2)
|
13
|
+
i18n (~> 0.5.0)
|
14
|
+
activesupport (3.0.9)
|
15
|
+
builder (2.1.2)
|
16
|
+
diff-lcs (1.1.2)
|
17
|
+
i18n (0.5.0)
|
18
|
+
rspec (2.6.0)
|
19
|
+
rspec-core (~> 2.6.0)
|
20
|
+
rspec-expectations (~> 2.6.0)
|
21
|
+
rspec-mocks (~> 2.6.0)
|
22
|
+
rspec-core (2.6.4)
|
23
|
+
rspec-expectations (2.6.0)
|
24
|
+
diff-lcs (~> 1.1.2)
|
25
|
+
rspec-mocks (2.6.0)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
ruby
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
email_validator!
|
32
|
+
rspec
|
data/README.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -1,49 +1,14 @@
|
|
1
|
-
require '
|
2
|
-
require 'rake'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "email_validator"
|
8
|
-
gem.summary = %Q{An email validator for Rails 3.}
|
9
|
-
gem.description = %Q{An email validator for Rails 3. See homepage for details: http://github.com/balexand/email_validator}
|
10
|
-
gem.email = "balexand@gmail.com"
|
11
|
-
gem.homepage = "http://github.com/balexand/email_validator"
|
12
|
-
gem.authors = ["Brian Alexander"]
|
13
|
-
gem.add_development_dependency "activerecord", ">= 0"
|
14
|
-
gem.add_development_dependency "sqlite3", ">= 0"
|
15
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
-
end
|
17
|
-
Jeweler::GemcutterTasks.new
|
18
|
-
rescue LoadError
|
19
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
-
end
|
21
|
-
|
1
|
+
require 'bundler'
|
22
2
|
require 'rake/testtask'
|
23
|
-
|
24
|
-
|
25
|
-
test.pattern = 'test/**/test_*.rb'
|
26
|
-
test.verbose = true
|
27
|
-
end
|
28
|
-
|
29
|
-
begin
|
30
|
-
require 'rcov/rcovtask'
|
31
|
-
Rcov::RcovTask.new do |test|
|
32
|
-
test.libs << 'test'
|
33
|
-
test.pattern = 'test/**/test_*.rb'
|
34
|
-
test.verbose = true
|
35
|
-
end
|
36
|
-
rescue LoadError
|
37
|
-
task :rcov do
|
38
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
39
|
-
end
|
40
|
-
end
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
require 'rspec/core/rake_task'
|
41
5
|
|
42
|
-
|
6
|
+
Bundler::GemHelper.install_tasks
|
43
7
|
|
44
|
-
|
8
|
+
RSpec::Core::RakeTask.new do |t|
|
9
|
+
t.rspec_opts = %w(--format documentation --colour)
|
10
|
+
end
|
45
11
|
|
46
|
-
require 'rake/rdoctask'
|
47
12
|
Rake::RDocTask.new do |rdoc|
|
48
13
|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
49
14
|
|
@@ -52,3 +17,5 @@ Rake::RDocTask.new do |rdoc|
|
|
52
17
|
rdoc.rdoc_files.include('README*')
|
53
18
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
54
19
|
end
|
20
|
+
|
21
|
+
task :default => 'spec'
|
data/email_validator.gemspec
CHANGED
@@ -1,13 +1,6 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
1
|
Gem::Specification.new do |s|
|
7
2
|
s.name = %q{email_validator}
|
8
|
-
s.version = "1.1
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
3
|
+
s.version = "1.2.1"
|
11
4
|
s.authors = ["Brian Alexander"]
|
12
5
|
s.date = %q{2011-07-23}
|
13
6
|
s.description = %q{An email validator for Rails 3. See homepage for details: http://github.com/balexand/email_validator}
|
@@ -16,36 +9,12 @@ Gem::Specification.new do |s|
|
|
16
9
|
"LICENSE",
|
17
10
|
"README.rdoc"
|
18
11
|
]
|
19
|
-
s.files =
|
20
|
-
|
21
|
-
"LICENSE",
|
22
|
-
"README.rdoc",
|
23
|
-
"Rakefile",
|
24
|
-
"VERSION",
|
25
|
-
"email_validator.gemspec",
|
26
|
-
"init.rb",
|
27
|
-
"lib/email_validator.rb",
|
28
|
-
"test/helper.rb",
|
29
|
-
"test/test_email_validator.rb"
|
30
|
-
]
|
12
|
+
s.files = `git ls-files`.split("\n")
|
13
|
+
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
31
14
|
s.homepage = %q{http://github.com/balexand/email_validator}
|
32
|
-
s.require_paths =
|
33
|
-
s.rubygems_version = %q{1.6.2}
|
15
|
+
s.require_paths = %w(lib)
|
34
16
|
s.summary = %q{An email validator for Rails 3.}
|
35
|
-
|
36
|
-
|
37
|
-
s.specification_version = 3
|
38
|
-
|
39
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
40
|
-
s.add_development_dependency(%q<activerecord>, [">= 0"])
|
41
|
-
s.add_development_dependency(%q<sqlite3>, [">= 0"])
|
42
|
-
else
|
43
|
-
s.add_dependency(%q<activerecord>, [">= 0"])
|
44
|
-
s.add_dependency(%q<sqlite3>, [">= 0"])
|
45
|
-
end
|
46
|
-
else
|
47
|
-
s.add_dependency(%q<activerecord>, [">= 0"])
|
48
|
-
s.add_dependency(%q<sqlite3>, [">= 0"])
|
49
|
-
end
|
17
|
+
s.add_dependency("activemodel", ">= 0")
|
18
|
+
s.add_development_dependency("rspec", ">= 0")
|
50
19
|
end
|
51
20
|
|
data/lib/email_validator.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# Based on work from http://thelucid.com/2010/01/08/sexy-validation-in-edge-rails-rails-3/
|
2
2
|
class EmailValidator < ActiveModel::EachValidator
|
3
3
|
def validate_each(record, attribute, value)
|
4
|
-
|
5
|
-
|
4
|
+
address, domain = value ? value.split('@') : ["", ""]
|
5
|
+
|
6
|
+
unless address.size <= 64 and domain.to_s.size <= 254 and value =~ /^([a-z0-9!\#$%&'*+\/=?^_`{|}~-]+(\.[a-z0-9!\#$%&'*+\/=?^_`{|}~-]+)*|"([\040-\041\043-\133\135-\176]|\134[\040-\176])*")@(\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]|((((([a-z0-9]{1}[a-z0-9-]+[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6}))|[a-z0-9]+\.xn\-\-[a-f0-9]+)$/i
|
7
|
+
record.errors.add(attribute, options[:message] || :invalid)
|
6
8
|
end
|
7
9
|
end
|
8
10
|
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class TestUser < TestModel
|
4
|
+
validates :email, :email => true
|
5
|
+
end
|
6
|
+
|
7
|
+
class TestUserWithMessage < TestModel
|
8
|
+
validates :email_address, :email => {:message => 'is not looking very good!'}
|
9
|
+
end
|
10
|
+
|
11
|
+
describe EmailValidator do
|
12
|
+
|
13
|
+
describe "validation" do
|
14
|
+
context "given the valid emails" do
|
15
|
+
[ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@letters-in-local.org",
|
16
|
+
"01234567890@numbers-in-local.net",
|
17
|
+
"&'*+-./=?^_{}~@other-valid-characters-in-local.net",
|
18
|
+
"mixed-1234-in-{+^}-local@sld.net",
|
19
|
+
"a@single-character-in-local.org",
|
20
|
+
"\"quoted\"@sld.com",
|
21
|
+
"\"\\e\\s\\c\\a\\p\\e\\d\"@sld.com",
|
22
|
+
"\"quoted-at-sign@sld.org\"@sld.com",
|
23
|
+
"\"escaped\\\"quote\"@sld.com",
|
24
|
+
"\"back\\slash\"@sld.com",
|
25
|
+
"one-character-third-level@a.example.com",
|
26
|
+
"single-character-in-sld@x.org",
|
27
|
+
"local@dash-in-sld.com",
|
28
|
+
"letters-in-sld@123.com",
|
29
|
+
"one-letter-sld@x.org",
|
30
|
+
"uncommon-tld@sld.museum",
|
31
|
+
"uncommon-tld@sld.travel",
|
32
|
+
"uncommon-tld@sld.mobi",
|
33
|
+
"country-code-tld@sld.uk",
|
34
|
+
"country-code-tld@sld.rw",
|
35
|
+
"local@sld.newTLD",
|
36
|
+
"punycode-numbers-in-tld@sld.xn--3e0b707e",
|
37
|
+
"local@sub.domains.com",
|
38
|
+
"bracketed-IP-instead-of-domain@[127.0.0.1]" ].each do |email|
|
39
|
+
|
40
|
+
it "#{email.inspect} should be valid" do
|
41
|
+
TestUser.new(:email => email).should be_valid
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
context "given the invalid emails" do
|
49
|
+
[ nil,
|
50
|
+
"@missing-local.org",
|
51
|
+
"! \#$%\`|@invalid-characters-in-local.org",
|
52
|
+
"(),:;\`|@more-invalid-characters-in-local.org",
|
53
|
+
"<>@[]\`|@even-more-invalid-characters-in-local.org",
|
54
|
+
".local-starts-with-dot@sld.com",
|
55
|
+
"local-ends-with-dot.@sld.com",
|
56
|
+
"two..consecutive-dots@sld.com",
|
57
|
+
"partially.\"quoted\"@sld.com",
|
58
|
+
"the-local-part-is-invalid-if-it-is-longer-than-sixty-four-characters@sld.net",
|
59
|
+
"missing-sld@.com",
|
60
|
+
"sld-starts-with-dashsh@-sld.com",
|
61
|
+
"sld-ends-with-dash@sld-.com",
|
62
|
+
"invalid-characters-in-sld@! \"\#$%(),/;<>_[]\`|.org",
|
63
|
+
"missing-dot-before-tld@com",
|
64
|
+
"missing-tld@sld.",
|
65
|
+
" ",
|
66
|
+
"the-total-length@of-an-entire-address-cannot-be-longer-than-two-hundred-and-fifty-four-characters-and-this-address-is-255-characters-exactly-so-it-should-be-invalid-and-im-going-to-add-some-more-words-here-to-increase-the-lenght-blah-blah-blah-blah-blah-blah-blah-blah.org",
|
67
|
+
"missing-at-sign.net",
|
68
|
+
"unbracketed-IP@127.0.0.1",
|
69
|
+
"invalid-ip@127.0.0.1.26",
|
70
|
+
"another-invalid-ip@127.0.0.256",
|
71
|
+
"IP-and-port@127.0.0.1:25" ].each do |email|
|
72
|
+
|
73
|
+
it "#{email.inspect} should not be valid" do
|
74
|
+
TestUser.new(:email => email).should_not be_valid
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "error messages" do
|
82
|
+
context "when the message is not defined" do
|
83
|
+
subject { TestUser.new :email => 'invalidemail@' }
|
84
|
+
before { subject.valid? }
|
85
|
+
|
86
|
+
it "should add the default message" do
|
87
|
+
subject.errors[:email].should include "is invalid"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context "when the message is defined" do
|
92
|
+
subject { TestUserWithMessage.new :email_address => 'invalidemail@' }
|
93
|
+
before { subject.valid? }
|
94
|
+
|
95
|
+
it "should add the customized message" do
|
96
|
+
subject.errors[:email_address].should include "is not looking very good!"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rspec'
|
3
|
+
require 'active_model'
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
6
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
7
|
+
|
8
|
+
require 'email_validator'
|
9
|
+
|
10
|
+
class TestModel
|
11
|
+
include ActiveModel::Validations
|
12
|
+
|
13
|
+
def initialize(attributes = {})
|
14
|
+
@attributes = attributes
|
15
|
+
end
|
16
|
+
|
17
|
+
def read_attribute_for_validation(key)
|
18
|
+
@attributes[key]
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: email_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1
|
4
|
+
version: 1.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,19 +13,19 @@ date: 2011-07-23 00:00:00.000000000 -07:00
|
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
17
|
-
requirement: &
|
16
|
+
name: activemodel
|
17
|
+
requirement: &70178441880860 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '0'
|
23
|
-
type: :
|
23
|
+
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70178441880860
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
|
-
name:
|
28
|
-
requirement: &
|
27
|
+
name: rspec
|
28
|
+
requirement: &70178441880380 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70178441880380
|
37
37
|
description: ! 'An email validator for Rails 3. See homepage for details: http://github.com/balexand/email_validator'
|
38
38
|
email: balexand@gmail.com
|
39
39
|
executables: []
|
@@ -43,15 +43,16 @@ extra_rdoc_files:
|
|
43
43
|
- README.rdoc
|
44
44
|
files:
|
45
45
|
- .document
|
46
|
+
- .gitignore
|
47
|
+
- Gemfile
|
48
|
+
- Gemfile.lock
|
46
49
|
- LICENSE
|
47
50
|
- README.rdoc
|
48
51
|
- Rakefile
|
49
|
-
- VERSION
|
50
52
|
- email_validator.gemspec
|
51
|
-
- init.rb
|
52
53
|
- lib/email_validator.rb
|
53
|
-
-
|
54
|
-
-
|
54
|
+
- spec/email_validator_spec.rb
|
55
|
+
- spec/spec_helper.rb
|
55
56
|
has_rdoc: true
|
56
57
|
homepage: http://github.com/balexand/email_validator
|
57
58
|
licenses: []
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.1.0
|
data/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'email_validator'
|
data/test/helper.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'test/unit'
|
3
|
-
require 'active_record'
|
4
|
-
|
5
|
-
# connect to in memory sqlite DB
|
6
|
-
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
7
|
-
|
8
|
-
ActiveRecord::Schema.define(:version => 1) do
|
9
|
-
create_table :test_users do |t|
|
10
|
-
t.string :email
|
11
|
-
end
|
12
|
-
|
13
|
-
create_table :test_user_with_messages do |t|
|
14
|
-
t.string :email
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
19
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
20
|
-
require 'email_validator'
|
21
|
-
|
22
|
-
class Test::Unit::TestCase
|
23
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestUser < ActiveRecord::Base
|
4
|
-
attr_accessor :email
|
5
|
-
validates :email, :email => true
|
6
|
-
end
|
7
|
-
|
8
|
-
class TestUserWithMessage < ActiveRecord::Base
|
9
|
-
attr_accessor :email_address
|
10
|
-
validates :email_address, :email => {:message => 'is not looking very good!'}
|
11
|
-
end
|
12
|
-
|
13
|
-
class TestEmailValidator < Test::Unit::TestCase
|
14
|
-
def email(email)
|
15
|
-
TestUser.new :email => email
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_should_accept_valid_email_addresses
|
19
|
-
email_addresses = %W{
|
20
|
-
foo@bar.com f@c.com nigel.worthington@big.co.uk f@s.co s@gmail.com foo@g-mail.com -@foo.com
|
21
|
-
areallylongnameaasdfasdfasdfasdf@asdfasdfasdfasdfasdf.ab.cd.ef.gh.co.ca
|
22
|
-
}
|
23
|
-
email_addresses.each do |email_address|
|
24
|
-
user = TestUser.new :email => email_address
|
25
|
-
assert user.valid?, "'#{email_address}' should be a valid address"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_should_reject_invalid_email_addresses
|
30
|
-
email_addresses = %W{
|
31
|
-
asdfasdf f@s f@s.c foo@bar@foo.com @bar.com foo@
|
32
|
-
}
|
33
|
-
email_addresses += [' foo@bar.com', 'foo@bar.com ', '', ' ', 'foo bar@gmail.com', 'foobar@g mail.com']
|
34
|
-
email_addresses.each do |email_address|
|
35
|
-
user = TestUser.new :email => email_address
|
36
|
-
assert !user.valid?, "'#{email_address}' should NOT be a valid address"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_should_properly_set_message
|
41
|
-
user = TestUser.new :email => 'invalidemail@'
|
42
|
-
assert !user.valid?
|
43
|
-
assert user.errors.full_messages.count == 1
|
44
|
-
assert user.errors.full_messages[0] == "Email is not valid"
|
45
|
-
|
46
|
-
user = TestUserWithMessage.new :email_address => 'invalidemail@'
|
47
|
-
assert !user.valid?
|
48
|
-
assert user.errors.full_messages.count == 1
|
49
|
-
assert user.errors.full_messages[0] == "Email address is not looking very good!"
|
50
|
-
end
|
51
|
-
end
|