email_validator 0.0.0.pre1
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/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +55 -0
- data/VERSION +1 -0
- data/email_validator.gemspec +61 -0
- data/init.rb +1 -0
- data/lib/email_validator.rb +8 -0
- data/test/helper.rb +24 -0
- data/test/test_email_validator.rb +51 -0
- metadata +123 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Brian Alexander
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
== Usage
|
2
|
+
|
3
|
+
Add to your Gemfile:
|
4
|
+
|
5
|
+
gem 'email_validator'
|
6
|
+
|
7
|
+
Run:
|
8
|
+
|
9
|
+
bundle install
|
10
|
+
|
11
|
+
The add the following to your model:
|
12
|
+
|
13
|
+
validates :my_email_attribute, :email => true
|
14
|
+
|
15
|
+
== Credit
|
16
|
+
|
17
|
+
Based on http://thelucid.com/2010/01/08/sexy-validation-in-edge-rails-rails-3/
|
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rubygems'
|
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 "thoughtbot-shoulda", ">= 0"
|
14
|
+
gem.add_development_dependency "activerecord", ">= 0"
|
15
|
+
gem.add_development_dependency "sqlite3-ruby", ">= 0"
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'rake/testtask'
|
24
|
+
Rake::TestTask.new(:test) do |test|
|
25
|
+
test.libs << 'lib' << 'test'
|
26
|
+
test.pattern = 'test/**/test_*.rb'
|
27
|
+
test.verbose = true
|
28
|
+
end
|
29
|
+
|
30
|
+
begin
|
31
|
+
require 'rcov/rcovtask'
|
32
|
+
Rcov::RcovTask.new do |test|
|
33
|
+
test.libs << 'test'
|
34
|
+
test.pattern = 'test/**/test_*.rb'
|
35
|
+
test.verbose = true
|
36
|
+
end
|
37
|
+
rescue LoadError
|
38
|
+
task :rcov do
|
39
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
task :test => :check_dependencies
|
44
|
+
|
45
|
+
task :default => :test
|
46
|
+
|
47
|
+
require 'rake/rdoctask'
|
48
|
+
Rake::RDocTask.new do |rdoc|
|
49
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "email_validator #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0.pre1
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{email_validator}
|
8
|
+
s.version = "0.0.0.pre1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Brian Alexander"]
|
12
|
+
s.date = %q{2010-08-21}
|
13
|
+
s.description = %q{An email validator for Rails 3. See homepage for details: http://github.com/balexand/email_validator}
|
14
|
+
s.email = %q{balexand@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"email_validator.gemspec",
|
27
|
+
"init.rb",
|
28
|
+
"lib/email_validator.rb",
|
29
|
+
"test/helper.rb",
|
30
|
+
"test/test_email_validator.rb"
|
31
|
+
]
|
32
|
+
s.homepage = %q{http://github.com/balexand/email_validator}
|
33
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
34
|
+
s.require_paths = ["lib"]
|
35
|
+
s.rubygems_version = %q{1.3.7}
|
36
|
+
s.summary = %q{An email validator for Rails 3.}
|
37
|
+
s.test_files = [
|
38
|
+
"test/helper.rb",
|
39
|
+
"test/test_email_validator.rb"
|
40
|
+
]
|
41
|
+
|
42
|
+
if s.respond_to? :specification_version then
|
43
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
44
|
+
s.specification_version = 3
|
45
|
+
|
46
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
48
|
+
s.add_development_dependency(%q<activerecord>, [">= 0"])
|
49
|
+
s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
52
|
+
s.add_dependency(%q<activerecord>, [">= 0"])
|
53
|
+
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
|
54
|
+
end
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
57
|
+
s.add_dependency(%q<activerecord>, [">= 0"])
|
58
|
+
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'email_validator'
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# Based on work from http://thelucid.com/2010/01/08/sexy-validation-in-edge-rails-rails-3/
|
2
|
+
class EmailValidator < ActiveModel::EachValidator
|
3
|
+
def validate_each(record, attribute, value)
|
4
|
+
unless value =~ /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
|
5
|
+
record.errors[attribute] << (options[:message] || "is not valid")
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
require 'active_record'
|
5
|
+
|
6
|
+
# connect to in memory sqlite DB
|
7
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
8
|
+
|
9
|
+
ActiveRecord::Schema.define(:version => 1) do
|
10
|
+
create_table :test_users do |t|
|
11
|
+
t.string :email
|
12
|
+
end
|
13
|
+
|
14
|
+
create_table :test_user_with_messages do |t|
|
15
|
+
t.string :email
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
20
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
21
|
+
require 'email_validator'
|
22
|
+
|
23
|
+
class Test::Unit::TestCase
|
24
|
+
end
|
@@ -0,0 +1,51 @@
|
|
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
|
+
should "accept valid email addresses" do
|
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
|
+
should "reject invalid email addresses" do
|
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
|
+
should "properly set message" do
|
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
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: email_validator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: -1876988192
|
5
|
+
prerelease: true
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
- pre1
|
11
|
+
version: 0.0.0.pre1
|
12
|
+
platform: ruby
|
13
|
+
authors:
|
14
|
+
- Brian Alexander
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2010-08-21 00:00:00 -07:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: thoughtbot-shoulda
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 3
|
31
|
+
segments:
|
32
|
+
- 0
|
33
|
+
version: "0"
|
34
|
+
type: :development
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: activerecord
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
version: "0"
|
48
|
+
type: :development
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: sqlite3-ruby
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
type: :development
|
63
|
+
version_requirements: *id003
|
64
|
+
description: "An email validator for Rails 3. See homepage for details: http://github.com/balexand/email_validator"
|
65
|
+
email: balexand@gmail.com
|
66
|
+
executables: []
|
67
|
+
|
68
|
+
extensions: []
|
69
|
+
|
70
|
+
extra_rdoc_files:
|
71
|
+
- LICENSE
|
72
|
+
- README.rdoc
|
73
|
+
files:
|
74
|
+
- .document
|
75
|
+
- .gitignore
|
76
|
+
- LICENSE
|
77
|
+
- README.rdoc
|
78
|
+
- Rakefile
|
79
|
+
- VERSION
|
80
|
+
- email_validator.gemspec
|
81
|
+
- init.rb
|
82
|
+
- lib/email_validator.rb
|
83
|
+
- test/helper.rb
|
84
|
+
- test/test_email_validator.rb
|
85
|
+
has_rdoc: true
|
86
|
+
homepage: http://github.com/balexand/email_validator
|
87
|
+
licenses: []
|
88
|
+
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options:
|
91
|
+
- --charset=UTF-8
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
hash: 3
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
version: "0"
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ">"
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
hash: 25
|
109
|
+
segments:
|
110
|
+
- 1
|
111
|
+
- 3
|
112
|
+
- 1
|
113
|
+
version: 1.3.1
|
114
|
+
requirements: []
|
115
|
+
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 1.3.7
|
118
|
+
signing_key:
|
119
|
+
specification_version: 3
|
120
|
+
summary: An email validator for Rails 3.
|
121
|
+
test_files:
|
122
|
+
- test/helper.rb
|
123
|
+
- test/test_email_validator.rb
|