dancroak-validates_email_format_of 1.2.1 → 1.2.2
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/CHANGELOG +2 -1
- data/README.markdown +4 -0
- data/Rakefile +12 -0
- data/test/test_helper.rb +5 -20
- data/test/validates_email_format_of_test.rb +37 -137
- data/validates_email_format_of.gemspec +26 -27
- metadata +15 -24
- data/Manifest +0 -15
- data/rakefile +0 -10
data/CHANGELOG
CHANGED
data/README.markdown
CHANGED
data/Rakefile
ADDED
data/test/test_helper.rb
CHANGED
@@ -10,7 +10,7 @@ ActiveRecord::Base.establish_connection(
|
|
10
10
|
:database => ':memory:')
|
11
11
|
|
12
12
|
ActiveRecord::Schema.define(:version => 0) do
|
13
|
-
create_table :
|
13
|
+
create_table :users, :force => true do |t|
|
14
14
|
t.column 'email', :string
|
15
15
|
end
|
16
16
|
end
|
@@ -19,43 +19,28 @@ class Person < ActiveRecord::Base
|
|
19
19
|
validates_email_format_of :email, :on => :create, :message => 'fails with custom message', :allow_nil => true
|
20
20
|
end
|
21
21
|
|
22
|
-
# Set up Feedback testing framework, a la carte
|
23
|
-
|
24
22
|
require 'test/unit'
|
25
23
|
require 'shoulda'
|
26
24
|
require "#{File.dirname(__FILE__)}/../init"
|
27
25
|
|
28
26
|
class Test::Unit::TestCase #:nodoc:
|
29
|
-
|
30
|
-
def self.should_allow_values(*good_values)
|
31
|
-
get_options!(good_values)
|
27
|
+
def self.should_allow_values(klass,*good_values)
|
32
28
|
good_values.each do |v|
|
33
29
|
should "allow email to be set to #{v.inspect}" do
|
34
|
-
user =
|
30
|
+
user = klass.new(:email => v)
|
35
31
|
user.save
|
36
32
|
assert_nil user.errors.on(:email)
|
37
33
|
end
|
38
34
|
end
|
39
35
|
end
|
40
36
|
|
41
|
-
def self.should_not_allow_values(
|
42
|
-
message = get_options!(bad_values, :message)
|
43
|
-
message ||= /invalid/
|
37
|
+
def self.should_not_allow_values(klass,*bad_values)
|
44
38
|
bad_values.each do |v|
|
45
39
|
should "not allow email to be set to #{v.inspect}" do
|
46
|
-
user =
|
40
|
+
user = klass.new(:email => v)
|
47
41
|
assert !user.save, "Saved user with email set to \"#{v}\""
|
48
42
|
assert user.errors.on(:email), "There are no errors set on email after being set to \"#{v}\""
|
49
43
|
end
|
50
44
|
end
|
51
45
|
end
|
52
|
-
|
53
|
-
def self.get_options!(args, *wanted)
|
54
|
-
ret = []
|
55
|
-
opts = (args.last.is_a?(Hash) ? args.pop : {})
|
56
|
-
wanted.each {|w| ret << opts.delete(w)}
|
57
|
-
raise ArgumentError, "Unsuported options given: #{opts.keys.join(', ')}" unless opts.keys.empty?
|
58
|
-
return *ret
|
59
|
-
end
|
60
|
-
|
61
46
|
end
|
@@ -1,137 +1,37 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
@@invalid_emails = ['invalid@example-com',
|
40
|
-
# period can not start local part
|
41
|
-
'.invalid@example.com',
|
42
|
-
# period can not end local part
|
43
|
-
'invalid.@example.com',
|
44
|
-
# period can not appear twice consecutively in local part
|
45
|
-
'invali..d@example.com',
|
46
|
-
'invalid@example.com.',
|
47
|
-
'invalid@example.com_',
|
48
|
-
'invalid@example.com-',
|
49
|
-
'invalid-example.com',
|
50
|
-
'invalid@example.b#r.com',
|
51
|
-
'invalid@example.c',
|
52
|
-
'invali d@example.com',
|
53
|
-
'invalidexample.com',
|
54
|
-
'invalid@example.']
|
55
|
-
|
56
|
-
def test_should_not_allow_invalid_email_addresses
|
57
|
-
@@invalid_emails.each do |email|
|
58
|
-
p = create_person(:email => email)
|
59
|
-
save_fails(p, email)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
@@quoted_emails = ['"Abc\@def"@example.com',
|
64
|
-
'"Fred\ Bloggs"@example.com',
|
65
|
-
'"Joe.\\Blow"@example.com',
|
66
|
-
]
|
67
|
-
|
68
|
-
# from http://www.rfc-editor.org/errata_search.php?rfc=3696
|
69
|
-
def test_should_allow_quoted_characters
|
70
|
-
@@quoted_emails.each do |email|
|
71
|
-
p = create_person(:email => email)
|
72
|
-
save_passes(p, email)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
@@unescaped_emails = ['Fred\ Bloggs_@example.com',
|
77
|
-
'Abc\@def+@example.com',
|
78
|
-
'Joe.\\Blow@example.com'
|
79
|
-
]
|
80
|
-
|
81
|
-
# from http://tools.ietf.org/html/rfc3696, page 5
|
82
|
-
# corrected in http://www.rfc-editor.org/errata_search.php?rfc=3696
|
83
|
-
def test_should_not_allow_escaped_characters_without_quotes
|
84
|
-
@@unescaped_emails.each do |email|
|
85
|
-
p = create_person(:email => email)
|
86
|
-
save_fails(p, email)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
@@long_emails = ['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@example.com',
|
91
|
-
'test@aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com'
|
92
|
-
]
|
93
|
-
|
94
|
-
def test_should_check_length_limits
|
95
|
-
@@long_emails.each do |email|
|
96
|
-
p = create_person(:email => email)
|
97
|
-
save_fails(p, email)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_should_respect_validate_on_option
|
102
|
-
p = create_person(:email => @@valid_email)
|
103
|
-
save_passes(p)
|
104
|
-
|
105
|
-
# we only asked to validate on :create so this should fail
|
106
|
-
assert p.update_attributes(:email => @@invalid_email)
|
107
|
-
assert_equal @@invalid_email, p.email
|
108
|
-
end
|
109
|
-
|
110
|
-
def test_should_allow_custom_error_message
|
111
|
-
p = create_person(:email => @@invalid_email)
|
112
|
-
save_fails(p)
|
113
|
-
assert_equal 'fails with custom message', p.errors.on(:email)
|
114
|
-
end
|
115
|
-
|
116
|
-
def test_should_allow_nil
|
117
|
-
p = create_person(:email => nil)
|
118
|
-
save_passes(p)
|
119
|
-
end
|
120
|
-
|
121
|
-
protected
|
122
|
-
def create_person(params)
|
123
|
-
Person.new(params)
|
124
|
-
end
|
125
|
-
|
126
|
-
def save_passes(p, email = '')
|
127
|
-
assert p.valid?, " validating #{email}"
|
128
|
-
assert p.save
|
129
|
-
assert_nil p.errors.on(:email)
|
130
|
-
end
|
131
|
-
|
132
|
-
def save_fails(p, email = '')
|
133
|
-
assert !p.valid?, " validating #{email}"
|
134
|
-
assert !p.save
|
135
|
-
assert p.errors.on(:email)
|
136
|
-
end
|
137
|
-
end
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
require File.dirname(__FILE__) + '/../shoulda_macros/validates_email_format_of'
|
3
|
+
|
4
|
+
class User < ActiveRecord::Base
|
5
|
+
validates_email_format_of :email,
|
6
|
+
:on => :create,
|
7
|
+
:message => 'fails with custom message',
|
8
|
+
:allow_nil => true
|
9
|
+
end
|
10
|
+
|
11
|
+
class ValidatesEmailFormatOfTest < Test::Unit::TestCase
|
12
|
+
should_validate_email_format_of_klass(User, :email)
|
13
|
+
|
14
|
+
context 'An invalid user on update' do
|
15
|
+
setup do
|
16
|
+
@user = User.new(:email => 'dcroak@thoughtbot.com')
|
17
|
+
assert @user.save
|
18
|
+
assert @user.update_attribute :email, '..dcroak@thoughtbot.com'
|
19
|
+
end
|
20
|
+
|
21
|
+
should 'pass validation' do
|
22
|
+
assert @user.valid?
|
23
|
+
assert @user.save
|
24
|
+
assert_nil @user.errors.on(:email)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'A user with a nil email' do
|
29
|
+
setup { @user = User.new(:email => nil) }
|
30
|
+
|
31
|
+
should 'pass validation' do
|
32
|
+
assert @user.valid?
|
33
|
+
assert @user.save
|
34
|
+
assert_nil @user.errors.on(:email)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -1,33 +1,32 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
|
-
s.name =
|
3
|
-
s.version = "1.2.
|
4
|
-
|
5
|
-
s.
|
6
|
-
s.
|
7
|
-
s.
|
8
|
-
s.
|
9
|
-
s.
|
10
|
-
|
11
|
-
|
2
|
+
s.name = "validates_email_format_of"
|
3
|
+
s.version = "1.2.2"
|
4
|
+
s.date = "2008-10-01"
|
5
|
+
s.summary = "Validate e-mail addreses against RFC 2822 and RFC 3696."
|
6
|
+
s.email = "dcroak@thoughtbot.com"
|
7
|
+
s.description = "Validate e-mail addreses against RFC 2822 and RFC 3696."
|
8
|
+
s.authors = ["Alex Dunae", "Dan Croak", "Mike Burns"]
|
9
|
+
s.extra_rdoc_files = ["CHANGELOG",
|
10
|
+
"lib/validates_email_format_of.rb",
|
11
|
+
"README.markdown"]
|
12
|
+
s.files = ["CHANGELOG",
|
13
|
+
"init.rb",
|
14
|
+
"lib/validates_email_format_of.rb",
|
15
|
+
"MIT-LICENSE",
|
16
|
+
"rails/init.rb",
|
17
|
+
"Rakefile",
|
18
|
+
"README",
|
19
|
+
"test/database.yml",
|
20
|
+
"test/fixtures/people.yml",
|
21
|
+
"test/fixtures/person.rb",
|
22
|
+
"test/schema.rb",
|
23
|
+
"test/test_helper.rb",
|
24
|
+
"test/validates_email_format_of_test.rb",
|
25
|
+
"Rakefile",
|
26
|
+
"validates_email_format_of.gemspec"]
|
12
27
|
s.has_rdoc = true
|
13
28
|
s.homepage = %q{http://code.dunae.ca/validates_email_format_of.html}
|
14
29
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Validates_email_format_of"]
|
15
30
|
s.require_paths = ["lib"]
|
16
|
-
s.rubyforge_project = %q{validates_email_format_of}
|
17
|
-
s.rubygems_version = %q{1.2.0}
|
18
|
-
s.summary = %q{Validate e-mail addreses against RFC 2822 and RFC 3696}
|
19
|
-
s.test_files = ["test/test_helper.rb", "test/validates_email_format_of_test.rb"]
|
20
|
-
|
21
|
-
if s.respond_to? :specification_version then
|
22
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
-
s.specification_version = 2
|
24
|
-
|
25
|
-
if current_version >= 3 then
|
26
|
-
s.add_development_dependency(%q<echoe>, [">= 0"])
|
27
|
-
else
|
28
|
-
s.add_dependency(%q<echoe>, [">= 0"])
|
29
|
-
end
|
30
|
-
else
|
31
|
-
s.add_dependency(%q<echoe>, [">= 0"])
|
32
|
-
end
|
33
31
|
end
|
32
|
+
|
metadata
CHANGED
@@ -1,28 +1,22 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dancroak-validates_email_format_of
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Dunae
|
8
|
+
- Dan Croak
|
9
|
+
- Mike Burns
|
8
10
|
autorequire:
|
9
11
|
bindir: bin
|
10
12
|
cert_chain: []
|
11
13
|
|
12
|
-
date: 2008-
|
14
|
+
date: 2008-10-01 00:00:00 -07:00
|
13
15
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
version_requirements: !ruby/object:Gem::Requirement
|
19
|
-
requirements:
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: "0"
|
23
|
-
version:
|
24
|
-
description: Validate e-mail addreses against RFC 2822 and RFC 3696
|
25
|
-
email: code@code.dunae.ca
|
16
|
+
dependencies: []
|
17
|
+
|
18
|
+
description: Validate e-mail addreses against RFC 2822 and RFC 3696.
|
19
|
+
email: dcroak@thoughtbot.com
|
26
20
|
executables: []
|
27
21
|
|
28
22
|
extensions: []
|
@@ -37,7 +31,7 @@ files:
|
|
37
31
|
- lib/validates_email_format_of.rb
|
38
32
|
- MIT-LICENSE
|
39
33
|
- rails/init.rb
|
40
|
-
-
|
34
|
+
- Rakefile
|
41
35
|
- README
|
42
36
|
- test/database.yml
|
43
37
|
- test/fixtures/people.yml
|
@@ -45,8 +39,6 @@ files:
|
|
45
39
|
- test/schema.rb
|
46
40
|
- test/test_helper.rb
|
47
41
|
- test/validates_email_format_of_test.rb
|
48
|
-
- Rakefile
|
49
|
-
- Manifest
|
50
42
|
- validates_email_format_of.gemspec
|
51
43
|
- README.markdown
|
52
44
|
has_rdoc: true
|
@@ -67,17 +59,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
67
59
|
version:
|
68
60
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
61
|
requirements:
|
70
|
-
- - "
|
62
|
+
- - ">="
|
71
63
|
- !ruby/object:Gem::Version
|
72
|
-
version: "
|
64
|
+
version: "0"
|
73
65
|
version:
|
74
66
|
requirements: []
|
75
67
|
|
76
|
-
rubyforge_project:
|
68
|
+
rubyforge_project:
|
77
69
|
rubygems_version: 1.2.0
|
78
70
|
signing_key:
|
79
71
|
specification_version: 2
|
80
|
-
summary: Validate e-mail addreses against RFC 2822 and RFC 3696
|
81
|
-
test_files:
|
82
|
-
|
83
|
-
- test/validates_email_format_of_test.rb
|
72
|
+
summary: Validate e-mail addreses against RFC 2822 and RFC 3696.
|
73
|
+
test_files: []
|
74
|
+
|
data/Manifest
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
CHANGELOG
|
2
|
-
init.rb
|
3
|
-
lib/validates_email_format_of.rb
|
4
|
-
MIT-LICENSE
|
5
|
-
rails/init.rb
|
6
|
-
rakefile
|
7
|
-
README.markdown
|
8
|
-
test/database.yml
|
9
|
-
test/fixtures/people.yml
|
10
|
-
test/fixtures/person.rb
|
11
|
-
test/schema.rb
|
12
|
-
test/test_helper.rb
|
13
|
-
test/validates_email_format_of_test.rb
|
14
|
-
Rakefile
|
15
|
-
Manifest
|
data/rakefile
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
require 'rake'
|
2
|
-
require 'echoe'
|
3
|
-
|
4
|
-
Echoe.new("validates_email_format_of") do |p|
|
5
|
-
p.author = "Alex Dunae"
|
6
|
-
p.summary = "Validate e-mail addreses against RFC 2822 and RFC 3696"
|
7
|
-
p.url = "http://code.dunae.ca/validates_email_format_of.html"
|
8
|
-
p.version = '1.2.1'
|
9
|
-
p.email = 'code@code.dunae.ca'
|
10
|
-
end
|