validate_email 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -39,8 +39,17 @@ The gem only supports Rails 3 (has dependencies in ActiveModel and ActiveSupport
39
39
 
40
40
  #### I18n
41
41
 
42
- The default error message `is not a valid email address`.
43
- You can pass the `:message => "my custom error"` option to your validation to define your own, custom message.
42
+ The error message will be looked up according to the standard ActiveModel::Errors scheme.
43
+ For the above Unicorn class this would be:
44
+
45
+ * activemodel.errors.models.unicorn.attributes.email_address.email
46
+ * activemodel.errors.models.unicorn.email
47
+ * activemodel.errors.messages.email
48
+ * errors.attributes.email_address.email
49
+ * errors.messages.email
50
+
51
+ A default errors.messages.email of `is not a valid email address` is provided.
52
+ You can also pass the `:message => "my custom error"` option to your validation to define your own custom message.
44
53
 
45
54
  ## Authors
46
55
 
@@ -49,4 +58,3 @@ You can pass the `:message => "my custom error"` option to your validation to de
49
58
 
50
59
  ## License
51
60
  Copyright 2010 by PerfectLine LLC (<http://www.perfectline.co.uk>) and is released under the MIT license.
52
-
@@ -0,0 +1,4 @@
1
+ en:
2
+ errors:
3
+ messages:
4
+ email: is not a valid email address
@@ -1,3 +1,5 @@
1
+ require 'active_support/i18n'
2
+ I18n.load_path << File.dirname(__FILE__) + '/locale/en.yml'
1
3
  require 'active_model'
2
4
  require 'mail'
3
5
 
@@ -6,12 +8,11 @@ module ActiveModel
6
8
  class EmailValidator < ActiveModel::EachValidator
7
9
 
8
10
  def initialize(options)
9
- options.reverse_merge!(:message => "is not a valid email address")
11
+ options.reverse_merge!(:message => :email)
10
12
  super(options)
11
13
  end
12
14
 
13
15
  def validate_each(record, attribute, value)
14
- return if options[:allow_nil] && value.nil?
15
16
 
16
17
  begin
17
18
  mail = Mail::Address.new(value)
metadata CHANGED
@@ -1,169 +1,149 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: validate_email
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 5
9
- version: 0.1.5
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.6
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Tanel Suurhans
13
9
  - Tarmo Lehtpuu
14
10
  autorequire:
15
11
  bindir: bin
16
12
  cert_chain: []
17
-
18
- date: 2010-11-03 00:00:00 +02:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
13
+ date: 2012-07-12 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
22
16
  name: rspec
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
25
18
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- segments:
30
- - 0
31
- version: "0"
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
32
23
  type: :development
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: diff-lcs
36
24
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: !ruby/object:Gem::Requirement
38
26
  none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- segments:
43
- - 1
44
- - 1
45
- - 2
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: diff-lcs
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
46
38
  version: 1.1.2
47
39
  type: :development
48
- version_requirements: *id002
49
- - !ruby/object:Gem::Dependency
50
- name: active_record
51
40
  prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
41
+ version_requirements: !ruby/object:Gem::Requirement
53
42
  none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- segments:
58
- - 3
59
- - 0
60
- - 0
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: 1.1.2
47
+ - !ruby/object:Gem::Dependency
48
+ name: active_record
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
61
54
  version: 3.0.0
62
55
  type: :development
63
- version_requirements: *id003
64
- - !ruby/object:Gem::Dependency
65
- name: sqlite3-ruby
66
56
  prerelease: false
67
- requirement: &id004 !ruby/object:Gem::Requirement
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: 3.0.0
63
+ - !ruby/object:Gem::Dependency
64
+ name: sqlite3-ruby
65
+ requirement: !ruby/object:Gem::Requirement
68
66
  none: false
69
- requirements:
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- segments:
73
- - 0
74
- version: "0"
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
75
71
  type: :development
76
- version_requirements: *id004
77
- - !ruby/object:Gem::Dependency
78
- name: mail
79
72
  prerelease: false
80
- requirement: &id005 !ruby/object:Gem::Requirement
73
+ version_requirements: !ruby/object:Gem::Requirement
81
74
  none: false
82
- requirements:
83
- - - ">="
84
- - !ruby/object:Gem::Version
85
- segments:
86
- - 2
87
- - 2
88
- - 5
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ - !ruby/object:Gem::Dependency
80
+ name: mail
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
89
86
  version: 2.2.5
90
87
  type: :runtime
91
- version_requirements: *id005
92
- - !ruby/object:Gem::Dependency
93
- name: activemodel
94
88
  prerelease: false
95
- requirement: &id006 !ruby/object:Gem::Requirement
89
+ version_requirements: !ruby/object:Gem::Requirement
96
90
  none: false
97
- requirements:
98
- - - ">="
99
- - !ruby/object:Gem::Version
100
- segments:
101
- - 3
102
- - 0
103
- version: "3.0"
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: 2.2.5
95
+ - !ruby/object:Gem::Dependency
96
+ name: activemodel
97
+ requirement: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '3.0'
104
103
  type: :runtime
105
- version_requirements: *id006
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
106
111
  description: Library for validating email addresses in Rails 3 models.
107
- email:
112
+ email:
108
113
  - tanel.suurhans@perfectline.ee
109
114
  - tarmo.lehtpuu@perfectline.ee
110
115
  executables: []
111
-
112
116
  extensions: []
113
-
114
- extra_rdoc_files:
117
+ extra_rdoc_files:
115
118
  - README.markdown
116
- files:
119
+ files:
117
120
  - README.markdown
118
121
  - init.rb
119
122
  - install.rb
123
+ - lib/locale/en.yml
120
124
  - lib/validate_email.rb
121
- - spec/resources/user.rb
122
- - spec/resources/user_with_ar.rb
123
- - spec/resources/user_with_ar_legacy.rb
124
- - spec/resources/user_with_blank.rb
125
- - spec/resources/user_with_legacy.rb
126
- - spec/resources/user_with_nil.rb
127
- - spec/spec_helper.rb
128
- - spec/validate_email_spec.rb
129
- has_rdoc: true
130
125
  homepage: http://github.com/perfectline/validates_email/tree/master
131
126
  licenses: []
132
-
133
127
  post_install_message:
134
- rdoc_options:
135
- - --charset=UTF-8
136
- require_paths:
128
+ rdoc_options: []
129
+ require_paths:
137
130
  - lib
138
- required_ruby_version: !ruby/object:Gem::Requirement
131
+ required_ruby_version: !ruby/object:Gem::Requirement
139
132
  none: false
140
- requirements:
141
- - - ">="
142
- - !ruby/object:Gem::Version
143
- segments:
144
- - 0
145
- version: "0"
146
- required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ! '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
138
  none: false
148
- requirements:
149
- - - ">="
150
- - !ruby/object:Gem::Version
151
- segments:
152
- - 0
153
- version: "0"
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
154
143
  requirements: []
155
-
156
144
  rubyforge_project:
157
- rubygems_version: 1.3.7
145
+ rubygems_version: 1.8.24
158
146
  signing_key:
159
147
  specification_version: 3
160
148
  summary: Library for validating email addresses in Rails 3 models.
161
- test_files:
162
- - spec/resources/user.rb
163
- - spec/resources/user_with_ar.rb
164
- - spec/resources/user_with_ar_legacy.rb
165
- - spec/resources/user_with_blank.rb
166
- - spec/resources/user_with_legacy.rb
167
- - spec/resources/user_with_nil.rb
168
- - spec/spec_helper.rb
169
- - spec/validate_email_spec.rb
149
+ test_files: []
@@ -1,7 +0,0 @@
1
- class User
2
- include ActiveModel::Validations
3
-
4
- attr_accessor :email_address
5
-
6
- validates :email_address, :email => true
7
- end
@@ -1,5 +0,0 @@
1
- class UserWithAr < ActiveRecord::Base
2
- self.table_name = "users"
3
-
4
- validates :email_address, :email => true
5
- end
@@ -1,5 +0,0 @@
1
- class UserWithArLegacy < ActiveRecord::Base
2
- self.table_name = "users"
3
-
4
- validates_email :email_address
5
- end
@@ -1,7 +0,0 @@
1
- class UserWithBlank
2
- include ActiveModel::Validations
3
-
4
- attr_accessor :email_address
5
-
6
- validates :email_address, :email => {:allow_blank => true}
7
- end
@@ -1,7 +0,0 @@
1
- class UserWithLegacy
2
- include ActiveModel::Validations
3
-
4
- attr_accessor :email_address
5
-
6
- validates_email :email_address, :allow_blank => true
7
- end
@@ -1,7 +0,0 @@
1
- class UserWithNil
2
- include ActiveModel::Validations
3
-
4
- attr_accessor :email_address
5
-
6
- validates :email_address, :email => {:allow_nil => true}
7
- end
@@ -1,24 +0,0 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
2
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/resources')
3
- $LOAD_PATH.unshift(File.dirname(__FILE__))
4
-
5
- require 'rspec'
6
- require 'sqlite3'
7
- require 'active_record'
8
- require 'active_record/base'
9
- require 'active_record/migration'
10
-
11
- ActiveRecord::Migration.verbose = false
12
- ActiveRecord::Base.establish_connection(
13
- "adapter" => "sqlite3",
14
- "database" => ":memory:"
15
- )
16
-
17
- require File.join(File.dirname(__FILE__), '..', 'init')
18
-
19
- autoload :User, 'resources/user'
20
- autoload :UserWithNil, 'resources/user_with_nil'
21
- autoload :UserWithBlank, 'resources/user_with_blank'
22
- autoload :UserWithLegacy, 'resources/user_with_legacy'
23
- autoload :UserWithAr, 'resources/user_with_ar'
24
- autoload :UserWithArLegacy, 'resources/user_with_ar_legacy'
@@ -1,150 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Email validation" do
4
-
5
- before(:all) do
6
- ActiveRecord::Schema.define(:version => 1) do
7
-
8
- create_table :users, :force => true do |t|
9
- t.column :email_address, :string
10
- end
11
-
12
- end
13
- end
14
-
15
- after(:all) do
16
- ActiveRecord::Base.connection.drop_table(:users)
17
- end
18
-
19
- context "with regular validator" do
20
- before do
21
- @user = User.new
22
- end
23
-
24
- it "should not allow nil as email" do
25
- @user.email_address = nil
26
- @user.should_not be_valid
27
- end
28
-
29
- it "should not allow blank as email" do
30
- @user.email_address = ""
31
- @user.should_not be_valid
32
- end
33
-
34
- it "should not allow an email without domain extension" do
35
- @user.email_address = "user@example"
36
- @user.should_not be_valid
37
- end
38
-
39
- it "should not allow an email without @" do
40
- @user.email_address = "user"
41
- @user.should_not be_valid
42
- end
43
-
44
- it "should not allow an email without prefix" do
45
- @user.email_address = "@example.com"
46
- @user.should_not be_valid
47
- end
48
-
49
- it "should not allow an email without domain" do
50
- @user.email_address = "user@.com"
51
- @user.should_not be_valid
52
- end
53
-
54
- it "should accept a valid email address" do
55
- @user.email_address = "user@example.com"
56
- @user.should be_valid
57
- end
58
- end
59
-
60
- context "with allow nil" do
61
- before do
62
- @user = UserWithNil.new
63
- end
64
-
65
- it "should allow nil as email" do
66
- @user.email_address = nil
67
- @user.should be_valid
68
- end
69
-
70
- it "should not allow blank as email" do
71
- @user.email_address = ""
72
- @user.should_not be_valid
73
- end
74
-
75
- it "shoild allow a valid email address" do
76
- @user.email_address = "user@example.com"
77
- @user.should be_valid
78
- end
79
- end
80
-
81
- context "with allow blank" do
82
- before do
83
- @user = UserWithBlank.new
84
- end
85
-
86
- it "should allow nil as email" do
87
- @user.email_address = nil
88
- @user.should be_valid
89
- end
90
-
91
- it "should allow blank as email" do
92
- @user.email_address = ""
93
- @user.should be_valid
94
- end
95
-
96
- it "should allow a valid email address" do
97
- @user.email_address = "user@example.com"
98
- @user.should be_valid
99
- end
100
- end
101
-
102
- context "with legacy syntax" do
103
- before do
104
- @user = UserWithLegacy.new
105
- end
106
-
107
- it "should allow nil as email" do
108
- @user.email_address = nil
109
- @user.should be_valid
110
- end
111
-
112
- it "should allow blank as email" do
113
- @user.email_address = ""
114
- @user.should be_valid
115
- end
116
-
117
- it "should allow a valid email address" do
118
- @user.email_address = "user@example.com"
119
- @user.should be_valid
120
- end
121
-
122
- it "should not allow invalid email" do
123
- @user.email_address = "random"
124
- @user.should_not be_valid
125
- end
126
- end
127
-
128
- context "with ActiveRecord" do
129
- before do
130
- @user = UserWithAr.new
131
- end
132
-
133
- it "should not allow invalid email" do
134
- @user.email_address = ""
135
- @user.should_not be_valid
136
- end
137
- end
138
-
139
- context "with ActiveRecord and legacy syntax" do
140
- before do
141
- @user = UserWithArLegacy.new
142
- end
143
-
144
- it "should not allow invalid email" do
145
- @user.email_address = ""
146
- @user.should_not be_valid
147
- end
148
- end
149
-
150
- end