validates_as_email_address 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,5 +1,9 @@
1
1
  *SVN*
2
2
 
3
+ *0.0.2* (May 5th, 2008)
4
+
5
+ * Update documentation
6
+
3
7
  *0.0.1* (September 26th, 2007)
4
8
 
5
9
  * Add documentation
data/README CHANGED
@@ -5,25 +5,21 @@ email addresses.
5
5
 
6
6
  == Resources
7
7
 
8
- API
9
-
10
- * http://api.pluginaweek.org/validates_as_email_address
11
-
12
8
  Wiki
13
9
 
14
10
  * http://wiki.pluginaweek.org/Validates_as_email_address
15
11
 
16
- Announcement
12
+ API
17
13
 
18
- * http://www.pluginaweek.org
14
+ * http://api.pluginaweek.org/validates_as_email_address
19
15
 
20
- Source
16
+ Development
21
17
 
22
- * http://svn.pluginaweek.org/trunk/plugins/active_record/validations/validates_as_email_address
18
+ * http://dev.pluginaweek.org/browser/trunk/validates_as_email_address
23
19
 
24
- Development
20
+ Source
25
21
 
26
- * http://dev.pluginaweek.org/browser/trunk/plugins/active_record/validations/validates_as_email_address
22
+ * http://svn.pluginaweek.org/trunk/validates_as_email_address
27
23
 
28
24
  == Description
29
25
 
@@ -41,6 +37,11 @@ the email address.
41
37
  validates_as_email_address :email, :on => :create
42
38
  end
43
39
 
40
+ == Testing
41
+
42
+ Before you can run any tests, the following gem must be installed:
43
+ * plugin_test_helper[http://wiki.pluginaweek.org/Plugin_test_helper]
44
+
44
45
  == References
45
46
 
46
47
  * Cal Henderson - {Parsing Email Adresses in PHP}[http://iamcal.com/publish/articles/php/parsing_email]
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'rake/gempackagetask'
4
4
  require 'rake/contrib/sshpublisher'
5
5
 
6
6
  PKG_NAME = 'validates_as_email_address'
7
- PKG_VERSION = '0.0.1'
7
+ PKG_VERSION = '0.0.2'
8
8
  PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
9
9
  RUBY_FORGE_PROJECT = 'pluginaweek'
10
10
 
@@ -39,8 +39,8 @@ spec = Gem::Specification.new do |s|
39
39
  s.has_rdoc = true
40
40
  s.test_files = Dir['test/**/*_test.rb']
41
41
 
42
- s.author = 'Aaron Pfeifer, Neil Abraham'
43
- s.email = 'info@pluginaweek.org'
42
+ s.author = 'Aaron Pfeifer'
43
+ s.email = 'aaron@pluginaweek.org'
44
44
  s.homepage = 'http://www.pluginaweek.org'
45
45
  end
46
46
 
@@ -52,12 +52,12 @@ end
52
52
 
53
53
  desc 'Publish the beta gem'
54
54
  task :pgem => [:package] do
55
- Rake::SshFilePublisher.new('pluginaweek@pluginaweek.org', '/home/pluginaweek/gems.pluginaweek.org/gems', 'pkg', "#{PKG_FILE_NAME}.gem").upload
55
+ Rake::SshFilePublisher.new('aaron@pluginaweek.org', '/home/aaron/gems.pluginaweek.org/public/gems', 'pkg', "#{PKG_FILE_NAME}.gem").upload
56
56
  end
57
57
 
58
58
  desc 'Publish the API documentation'
59
59
  task :pdoc => [:rdoc] do
60
- Rake::SshDirPublisher.new('pluginaweek@pluginaweek.org', "/home/pluginaweek/api.pluginaweek.org/#{PKG_NAME}", 'rdoc').upload
60
+ Rake::SshDirPublisher.new('aaron@pluginaweek.org', "/home/aaron/api.pluginaweek.org/public/#{PKG_NAME}", 'rdoc').upload
61
61
  end
62
62
 
63
63
  desc 'Publish the API docs and gem'
@@ -69,7 +69,7 @@ task :release => [:gem, :package] do
69
69
 
70
70
  ruby_forge = RubyForge.new
71
71
  ruby_forge.login
72
-
72
+
73
73
  %w( gem tgz zip ).each do |ext|
74
74
  file = "pkg/#{PKG_FILE_NAME}.#{ext}"
75
75
  puts "Releasing #{File.basename(file)}..."
@@ -1,102 +1,83 @@
1
- # The standard describing the format of email addresses
2
- module RFC822
3
- EmailAddress = begin
4
- qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]'
5
- dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]'
6
- atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+'
7
- quoted_pair = '\\x5c[\\x00-\\x7f]'
8
- domain_literal = "\\x5b(?:#{dtext}|#{quoted_pair})*\\x5d"
9
- quoted_string = "\\x22(?:#{qtext}|#{quoted_pair})*\\x22"
10
- domain_ref = atom
11
- sub_domain = "(?:#{domain_ref}|#{domain_literal})"
12
- word = "(?:#{atom}|#{quoted_string})"
13
- domain = "#{sub_domain}(?:\\x2e#{sub_domain})*"
14
- local_part = "#{word}(?:\\x2e#{word})*"
15
- addr_spec = "(#{local_part})\\x40(#{domain})"
16
- pattern = /\A#{addr_spec}\z/
17
- end
18
- end
1
+ require 'validates_as_email_address/rfc_822'
19
2
 
20
3
  module PluginAWeek #:nodoc:
21
- module Validates #:nodoc:
22
- # Adds validations for email addresses
23
- module EmailAddress
24
- # The options that can be used when validating the format of the email address
25
- EMAIL_FORMAT_OPTIONS = [
26
- :wrong_format,
27
- :allow_nil,
28
- :on,
29
- :if
30
- ]
4
+ # Adds validations for email addresses
5
+ module ValidatesAsEmailAddress
6
+ # The options that can be used when validating the format of the email address
7
+ EMAIL_FORMAT_OPTIONS = [
8
+ :wrong_format,
9
+ :allow_nil,
10
+ :on,
11
+ :if
12
+ ]
13
+
14
+ # The options that can be used when validating the length of the email address
15
+ EMAIL_LENGTH_OPTIONS = [
16
+ :minimum,
17
+ :maximum,
18
+ :is,
19
+ :within,
20
+ :in,
21
+ :too_long,
22
+ :too_short,
23
+ :wrong_length,
24
+ :allow_nil,
25
+ :on,
26
+ :if
27
+ ]
28
+
29
+ # Validates whether the value of the specific attribute matches against the
30
+ # RFC822 specificiation.
31
+ #
32
+ # class Person < ActiveRecord::Base
33
+ # validates_as_email_address :email, :on => :create
34
+ # end
35
+ #
36
+ # This will also validate that the email address is within the specification
37
+ # limits, specifically between 3 and 320 characters in length.
38
+ #
39
+ # Configuration options for length:
40
+ # * +minimum+ - The minimum size of the attribute
41
+ # * +maximum+ - The maximum size of the attribute
42
+ # * +is+ - The exact size of the attribute
43
+ # * +within+ - A range specifying the minimum and maximum size of the attribute
44
+ # * +in+ - A synonym(or alias) for :within
45
+ # * +too_long+ - The error message if the attribute goes over the maximum (default is: "is too long (maximum is %d characters)")
46
+ # * +too_short+ - The error message if the attribute goes under the minimum (default is: "is too short (minimum is %d characters)")
47
+ # * +wrong_length+ - The error message if using the :is method and the attribute is the wrong size (default is: "is the wrong length (should be %d characters)")
48
+ #
49
+ # Configuration options for format:
50
+ # * +wrong_format+ - A custom error message (default is: "is an invalid email address")
51
+ #
52
+ # Configuration options for both length and format:
53
+ # * +allow_nil+ - Attribute may be nil; skip validation.
54
+ # * +on+ - Specifies when this validation is active (default is :save, other options :create, :update)
55
+ # * +if+ - Specifies a method, proc or string to call to determine if the validation should
56
+ # occur (e.g. :if => :allow_validation, or :if => Proc.new { |user| user.signup_step > 2 }). The
57
+ # method, proc or string should return or evaluate to a true or false value.
58
+ def validates_as_email_address(*attr_names)
59
+ configuration = attr_names.last.is_a?(Hash) ? attr_names.pop : {}
60
+ configuration.assert_valid_keys(EMAIL_FORMAT_OPTIONS | EMAIL_LENGTH_OPTIONS)
61
+ configuration.reverse_merge!(
62
+ :wrong_format => ActiveRecord::Errors.default_error_messages[:invalid_email]
63
+ )
31
64
 
32
- # The options that can be used when validating the length of the email address
33
- EMAIL_LENGTH_OPTIONS = [
34
- :minimum,
35
- :maximum,
36
- :is,
37
- :within,
38
- :in,
39
- :too_long,
40
- :too_short,
41
- :wrong_length,
42
- :allow_nil,
43
- :on,
44
- :if
45
- ]
65
+ # Add format validation
66
+ format_configuration = configuration.reject {|key, value| !EMAIL_FORMAT_OPTIONS.include?(key)}
67
+ format_configuration[:message] = format_configuration.delete(:wrong_format)
68
+ format_configuration[:with] = RFC822::EmailAddress
69
+ validates_format_of attr_names, format_configuration
46
70
 
47
- # Validates whether the value of the specific attribute matches against the
48
- # RFC822 specificiation.
49
- #
50
- # class Person < ActiveRecord::Base
51
- # validates_as_email_address :email, :on => :create
52
- # end
53
- #
54
- # This will also validate that the email address is within the specification
55
- # limits, specifically between 3 and 320 characters in length.
56
- #
57
- # Configuration options for length:
58
- # * +minimum+ - The minimum size of the attribute
59
- # * +maximum+ - The maximum size of the attribute
60
- # * +is+ - The exact size of the attribute
61
- # * +within+ - A range specifying the minimum and maximum size of the attribute
62
- # * +in+ - A synonym(or alias) for :within
63
- # * +too_long+ - The error message if the attribute goes over the maximum (default is: "is too long (maximum is %d characters)")
64
- # * +too_short+ - The error message if the attribute goes under the minimum (default is: "is too short (minimum is %d characters)")
65
- # * +wrong_length+ - The error message if using the :is method and the attribute is the wrong size (default is: "is the wrong length (should be %d characters)")
66
- #
67
- # Configuration options for format:
68
- # * +wrong_format+ - A custom error message (default is: "is an invalid email address")
69
- #
70
- # Configuration options for both length and format:
71
- # * +allow_nil+ - Attribute may be nil; skip validation.
72
- # * +on+ - Specifies when this validation is active (default is :save, other options :create, :update)
73
- # * +if+ - Specifies a method, proc or string to call to determine if the validation should
74
- # occur (e.g. :if => :allow_validation, or :if => Proc.new { |user| user.signup_step > 2 }). The
75
- # method, proc or string should return or evaluate to a true or false value.
76
- def validates_as_email_address(*attr_names)
77
- configuration = attr_names.last.is_a?(Hash) ? attr_names.pop : {}
78
- configuration.assert_valid_keys(EMAIL_FORMAT_OPTIONS | EMAIL_LENGTH_OPTIONS)
79
- configuration.reverse_merge!(
80
- :wrong_format => ActiveRecord::Errors.default_error_messages[:invalid_email]
81
- )
82
-
83
- # Add format validation
84
- format_configuration = configuration.reject {|key, value| !EMAIL_FORMAT_OPTIONS.include?(key)}
85
- format_configuration[:message] = format_configuration.delete(:wrong_format)
86
- format_configuration[:with] = RFC822::EmailAddress
87
- validates_format_of attr_names, format_configuration
88
-
89
- # Add length validation
90
- length_configuration = configuration.reject {|key, value| !EMAIL_LENGTH_OPTIONS.include?(key)}
91
- length_configuration.reverse_merge!(:within => 3..320)
92
- validates_length_of attr_names, length_configuration
93
- end
71
+ # Add length validation
72
+ length_configuration = configuration.reject {|key, value| !EMAIL_LENGTH_OPTIONS.include?(key)}
73
+ length_configuration.reverse_merge!(:within => 3..320)
74
+ validates_length_of attr_names, length_configuration
94
75
  end
95
76
  end
96
77
  end
97
78
 
98
79
  ActiveRecord::Base.class_eval do
99
- extend PluginAWeek::Validates::EmailAddress
80
+ extend PluginAWeek::ValidatesAsEmailAddress
100
81
  end
101
82
 
102
83
  ActiveRecord::Errors.default_error_messages.update(
@@ -0,0 +1,18 @@
1
+ # The standard describing the format of email addresses
2
+ module RFC822
3
+ EmailAddress = begin
4
+ qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]'
5
+ dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]'
6
+ atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+'
7
+ quoted_pair = '\\x5c[\\x00-\\x7f]'
8
+ domain_literal = "\\x5b(?:#{dtext}|#{quoted_pair})*\\x5d"
9
+ quoted_string = "\\x22(?:#{qtext}|#{quoted_pair})*\\x22"
10
+ domain_ref = atom
11
+ sub_domain = "(?:#{domain_ref}|#{domain_literal})"
12
+ word = "(?:#{atom}|#{quoted_string})"
13
+ domain = "#{sub_domain}(?:\\x2e#{sub_domain})*"
14
+ local_part = "#{word}(?:\\x2e#{word})*"
15
+ addr_spec = "(#{local_part})\\x40(#{domain})"
16
+ pattern = /\A#{addr_spec}\z/
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ class User < ActiveRecord::Base
2
+ validates_as_email_address :email
3
+ end
@@ -0,0 +1,11 @@
1
+ class CreateUsers < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :users do |t|
4
+ t.string :email, :null => false, :limit => 320
5
+ end
6
+ end
7
+
8
+ def self.down
9
+ drop_table :users
10
+ end
11
+ end
@@ -0,0 +1,39 @@
1
+ # Logfile created on Sun Apr 06 00:59:11 -0400 2008 SQL (0.000430) select sqlite_version(*)
2
+ SQL (0.000442) CREATE TABLE "schema_info" (version varchar(255))
3
+ SQL (0.000121) INSERT INTO "schema_info" (version) VALUES(0)
4
+ SQL (0.000224) SELECT version FROM schema_info
5
+ Migrating to CreateUsers (1)
6
+ SQL (0.000223)  SELECT name
7
+ FROM sqlite_master
8
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
9
+ 
10
+ SQL (0.000428) select sqlite_version(*)
11
+ SQL (0.000429) CREATE TABLE "schema_info" (version varchar(255))
12
+ SQL (0.000115) INSERT INTO "schema_info" (version) VALUES(0)
13
+ SQL (0.000221) SELECT version FROM schema_info
14
+ Migrating to CreateUsers (1)
15
+ SQL (0.000359) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(320) NOT NULL) 
16
+ SQL (0.000106) UPDATE schema_info SET version = 1
17
+ SQL (0.000431) select sqlite_version(*)
18
+ SQL (0.000426) CREATE TABLE "schema_info" (version varchar(255))
19
+ SQL (0.000114) INSERT INTO "schema_info" (version) VALUES(0)
20
+ SQL (0.000224) SELECT version FROM schema_info
21
+ Migrating to CreateUsers (1)
22
+ SQL (0.000352) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(320) NOT NULL) 
23
+ SQL (0.000105) UPDATE schema_info SET version = 1
24
+ SQL (0.000460)  SELECT name
25
+ FROM sqlite_master
26
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
27
+ 
28
+ SQL (0.000260) select sqlite_version(*)
29
+ SQL (0.000324) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
30
+ SQL (0.000255) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
31
+ SQL (0.000211)  SELECT name
32
+ FROM sqlite_master
33
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
34
+ 
35
+ SQL (0.000150) SELECT version FROM schema_migrations
36
+ Migrating to CreateUsers (1)
37
+ SQL (0.000093) SELECT version FROM schema_migrations
38
+ SQL (0.000361) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(320) NOT NULL) 
39
+ SQL (0.000151) INSERT INTO schema_migrations (version) VALUES ('1')
data/test/test_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
- require 'test/unit'
1
+ # Load the plugin testing framework
2
+ $:.unshift("#{File.dirname(__FILE__)}/../../plugin_test_helper/lib")
2
3
  require 'rubygems'
3
- require 'active_record'
4
+ require 'plugin_test_helper'
4
5
 
5
- $:.unshift(File.dirname(__FILE__) + '/../lib')
6
- require File.dirname(__FILE__) + '/../init'
6
+ # Run the migrations
7
+ ActiveRecord::Migrator.migrate("#{RAILS_ROOT}/db/migrate")
@@ -1,16 +1,7 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- class User < ActiveRecord::Base
4
- def self.columns
5
- []
6
- end
7
-
8
- attr_accessor :email
9
- validates_as_email_address :email
10
- end
1
+ require File.dirname(__FILE__) + '/../test_helper'
11
2
 
12
3
  class ValidatesAsEmailAddressTest < Test::Unit::TestCase
13
- def test_illegal_rfc822_email_address_should_not_be_valid
4
+ def test_should_require_legal_rfc822_format
14
5
  [
15
6
  'Max@Job 3:14',
16
7
  'Job@Book of Job',
@@ -18,9 +9,7 @@ class ValidatesAsEmailAddressTest < Test::Unit::TestCase
18
9
  ].each do |address|
19
10
  assert !User.new(:email => address).valid?, "#{address} should be illegal."
20
11
  end
21
- end
22
-
23
- def test_legal_rfc822_email_address_should_be_valid
12
+
24
13
  [
25
14
  'test@example',
26
15
  'test@example.com',
@@ -32,4 +21,9 @@ class ValidatesAsEmailAddressTest < Test::Unit::TestCase
32
21
  assert User.new(:email => address).valid?, "#{address} should be legal."
33
22
  end
34
23
  end
24
+
25
+ def test_not_allow_email_addresses_longer_than_320_characters
26
+ assert User.new(:email => 'a' * 314 + '@a.com').valid?
27
+ assert !User.new(:email => 'a' * 315 + '@a.com').valid?
28
+ end
35
29
  end
metadata CHANGED
@@ -1,53 +1,72 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: validates_as_email_address
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.0.1
7
- date: 2007-09-26 00:00:00 -04:00
8
- summary: Adds support for validating the format/length of email addresses
9
- require_paths:
10
- - lib
11
- email: info@pluginaweek.org
12
- homepage: http://www.pluginaweek.org
13
- rubyforge_project:
14
- description:
15
- autorequire: validates_as_email_address
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 0.0.2
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
- - Aaron Pfeifer, Neil Abraham
7
+ - Aaron Pfeifer
8
+ autorequire: validates_as_email_address
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-05-05 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: aaron@pluginaweek.org
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
31
24
  files:
32
25
  - lib/validates_as_email_address.rb
26
+ - lib/validates_as_email_address
27
+ - lib/validates_as_email_address/rfc_822.rb
28
+ - test/app_root
29
+ - test/app_root/log
30
+ - test/app_root/log/in_memory.log
31
+ - test/app_root/db
32
+ - test/app_root/db/migrate
33
+ - test/app_root/db/migrate/001_create_users.rb
34
+ - test/app_root/app
35
+ - test/app_root/app/models
36
+ - test/app_root/app/models/user.rb
33
37
  - test/test_helper.rb
34
- - test/validates_as_email_address_test.rb
38
+ - test/unit
39
+ - test/unit/validates_as_email_address_test.rb
35
40
  - CHANGELOG
36
41
  - init.rb
37
42
  - LICENSE
38
43
  - Rakefile
39
44
  - README
40
- test_files:
41
- - test/validates_as_email_address_test.rb
45
+ has_rdoc: true
46
+ homepage: http://www.pluginaweek.org
47
+ post_install_message:
42
48
  rdoc_options: []
43
49
 
44
- extra_rdoc_files: []
45
-
46
- executables: []
47
-
48
- extensions: []
49
-
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
50
64
  requirements: []
51
65
 
52
- dependencies: []
53
-
66
+ rubyforge_project:
67
+ rubygems_version: 1.1.0
68
+ signing_key:
69
+ specification_version: 2
70
+ summary: Adds support for validating the format/length of email addresses
71
+ test_files:
72
+ - test/unit/validates_as_email_address_test.rb