dancroak-validates_email_format_of 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -18,4 +18,5 @@
18
18
  * added :unless option
19
19
 
20
20
  == Unreleased
21
- * Now available as a gem on GitHub
21
+ * Now available as a gem on GitHub
22
+ * added should_validate_email_format_of
data/README.markdown CHANGED
@@ -5,6 +5,10 @@ Validate various formats of email address against RFC 2822.
5
5
 
6
6
  Usage
7
7
  -----
8
+
9
+ class PersonTest < ActiveSupport::TestCase
10
+ should_validate_email_format_of :email
11
+ end
8
12
 
9
13
  class Person < ActiveRecord::Base
10
14
  validates_email_format_of :email
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+
4
+ test_files_pattern = 'test/*_test.rb'
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'lib'
7
+ t.pattern = test_files_pattern
8
+ t.verbose = false
9
+ end
10
+
11
+ desc "Run the test suite"
12
+ task :default => :test
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 :people, :force => true do |t|
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 = User.new(:email => v)
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(*bad_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 = User.new(:email => v)
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
- class ValidatesEmailFormatOfTest < Test::Unit::TestCase
4
- @@valid_email = 'valid@example.com'
5
- @@invalid_email = 'invalid@example.'
6
-
7
- @@valid_emails = ['valid@example.com',
8
- 'Valid@test.example.com',
9
- 'valid+valid123@test.example.com',
10
- 'valid_valid123@test.example.com',
11
- 'valid-valid+123@test.example.co.uk',
12
- 'valid-valid+1.23@test.example.com.au',
13
- 'valid@example.co.uk',
14
- 'v@example.com',
15
- 'valid@example.ca',
16
- 'valid_@example.com',
17
- 'valid123.456@example.org',
18
- 'valid123.456@example.travel',
19
- 'valid123.456@example.museum',
20
- 'valid@example.mobi',
21
- 'valid@example.info',
22
- 'valid-@example.com',
23
- # from RFC 3696, page 6
24
- 'customer/department=shipping@example.com',
25
- '$A12345@example.com',
26
- '!def!xyz%abc@example.com',
27
- '_somename@example.com',
28
- # apostrophes
29
- "test'test@example.com",
30
- ]
31
-
32
- def test_should_allow_valid_email_addresses
33
- @@valid_emails.each do |email|
34
- p = create_person(:email => email)
35
- save_passes(p, email)
36
- end
37
- end
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 = %q{validates_email_format_of}
3
- s.version = "1.2.1"
4
-
5
- s.required_rubygems_version = Gem::Requirement.new("= 1.2") if s.respond_to? :required_rubygems_version=
6
- s.authors = ["Alex Dunae"]
7
- s.date = %q{2008-07-02}
8
- s.description = %q{Validate e-mail addreses against RFC 2822 and RFC 3696}
9
- s.email = %q{code@code.dunae.ca}
10
- s.extra_rdoc_files = ["CHANGELOG", "lib/validates_email_format_of.rb", "README.markdown"]
11
- s.files = ["CHANGELOG", "init.rb", "lib/validates_email_format_of.rb", "MIT-LICENSE", "rails/init.rb", "rakefile", "README", "test/database.yml", "test/fixtures/people.yml", "test/fixtures/person.rb", "test/schema.rb", "test/test_helper.rb", "test/validates_email_format_of_test.rb", "Rakefile", "Manifest", "validates_email_format_of.gemspec"]
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.1
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-07-02 00:00:00 -07:00
14
+ date: 2008-10-01 00:00:00 -07:00
13
15
  default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: echoe
17
- version_requirement:
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
- - rakefile
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: "1.2"
64
+ version: "0"
73
65
  version:
74
66
  requirements: []
75
67
 
76
- rubyforge_project: validates_email_format_of
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
- - test/test_helper.rb
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