valid_email 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -42,7 +42,7 @@ Or
42
42
 
43
43
  If you don't want the MX validator stuff, just require the right file
44
44
 
45
- require 'valid\_email/email_validator'
45
+ require 'valid_email/email_validator'
46
46
 
47
47
  Or in your Gemfile
48
48
 
@@ -0,0 +1,5 @@
1
+ en:
2
+ active_record:
3
+ validations:
4
+ email:
5
+ invalid: "is invalid"
@@ -0,0 +1,5 @@
1
+ fr:
2
+ active_record:
3
+ validations:
4
+ email:
5
+ invalid: "est invalide"
@@ -23,6 +23,6 @@ class EmailValidator < ActiveModel::EachValidator
23
23
  rescue Exception => e
24
24
  r = false
25
25
  end
26
- record.errors.add attribute, (options[:message] || "is invalid") unless r
26
+ record.errors.add attribute, (options[:message] || I18n.t(:invalid, :scope => "active_record.validations.email")) unless r
27
27
  end
28
28
  end
@@ -10,7 +10,7 @@ class MxValidator < ActiveModel::EachValidator
10
10
  mx.concat dns.getresources(m.domain, Resolv::DNS::Resource::IN::MX)
11
11
  end
12
12
  r = mx.size > 0
13
- record.errors.add attribute, (options[:message] || "is invalid") unless r
13
+ record.errors.add attribute, (options[:message] || I18n.t(:invalid, :scope => "active_record.validations.email")) unless r
14
14
  r
15
15
  end
16
16
  end
@@ -1,2 +1,2 @@
1
- ValidEmailVersion = "0.0.2"
1
+ ValidEmailVersion = "0.0.3"
2
2
 
data/lib/valid_email.rb CHANGED
@@ -1,2 +1,2 @@
1
1
  require 'valid_email/all'
2
-
2
+ I18n.load_path += Dir.glob(File.expand_path('../../config/locales/**/*',__FILE__))
@@ -7,74 +7,93 @@ describe EmailValidator do
7
7
  validates :email, :email => true
8
8
  end
9
9
 
10
-
11
-
12
- describe "validating email" do
13
- subject { person_class.new }
14
-
15
- it "should fail when email empty" do
16
- subject.valid?.should be_false
17
- subject.errors[:email].should == [ "is invalid" ]
18
- end
19
-
20
- it "should fail when email is not valid" do
21
- subject.email = 'joh@doe'
22
- subject.valid?.should be_false
23
- subject.errors[:email].should == [ "is invalid" ]
24
- end
25
-
26
- it "should fail when email is valid with information" do
27
- subject.email = '"John Doe" <john@doe.com>'
28
- subject.valid?.should be_false
29
- subject.errors[:email].should == [ "is invalid" ]
30
- end
31
-
32
- it "should pass when email is simple email address" do
33
- subject.email = 'john@doe.com'
34
- subject.valid?.should be_true
35
- subject.errors[:email].should be_empty
36
- end
37
-
38
- it "should fail when email is simple email address not stripped" do
39
- subject.email = 'john@doe.com '
40
- subject.valid?.should be_false
41
- subject.errors[:email].should == [ "is invalid" ]
42
- end
43
-
44
-
45
- it "should fail when passing multiple simple email addresses" do
46
- subject.email = 'john@doe.com, maria@doe.com'
47
- subject.valid?.should be_false
48
- subject.errors[:email].should == [ "is invalid" ]
49
- end
50
- end
51
-
52
10
  person_class_mx = Class.new do
53
11
  include ActiveModel::Validations
54
12
  attr_accessor :email
55
13
  validates :email, :email => {:mx => true}
56
14
  end
57
15
 
58
- describe "validating email with MX" do
59
- subject { person_class_mx.new }
60
16
 
61
- it "should pass when email domain has MX record" do
62
- subject.email = 'john@gmail.com'
63
- subject.valid?.should be_true
64
- subject.errors[:email].should be_empty
17
+ shared_examples_for "Validating emails" do
18
+
19
+ before :each do
20
+ I18n.locale = locale
65
21
  end
66
22
 
67
- it "should fail when email domain has no MX record" do
68
- subject.email = 'john@subdomain.rubyonrails.org'
69
- subject.valid?.should be_false
70
- subject.errors[:email].should == [ "is invalid" ]
71
- end
23
+ describe "validating email" do
24
+ subject { person_class.new }
25
+
26
+ it "should fail when email empty" do
27
+ subject.valid?.should be_false
28
+ subject.errors[:email].should == errors
29
+ end
30
+
31
+ it "should fail when email is not valid" do
32
+ subject.email = 'joh@doe'
33
+ subject.valid?.should be_false
34
+ subject.errors[:email].should == errors
35
+ end
36
+
37
+ it "should fail when email is valid with information" do
38
+ subject.email = '"John Doe" <john@doe.com>'
39
+ subject.valid?.should be_false
40
+ subject.errors[:email].should == errors
41
+ end
42
+
43
+ it "should pass when email is simple email address" do
44
+ subject.email = 'john@doe.com'
45
+ subject.valid?.should be_true
46
+ subject.errors[:email].should be_empty
47
+ end
48
+
49
+ it "should fail when email is simple email address not stripped" do
50
+ subject.email = 'john@doe.com '
51
+ subject.valid?.should be_false
52
+ subject.errors[:email].should == errors
53
+ end
54
+
55
+ it "should fail when passing multiple simple email addresses" do
56
+ subject.email = 'john@doe.com, maria@doe.com'
57
+ subject.valid?.should be_false
58
+ subject.errors[:email].should == errors
59
+ end
72
60
 
73
- it "should fail when domain does not exists" do
74
- subject.email = 'john@nonexistentdomain.abc'
75
- subject.valid?.should be_false
76
- subject.errors[:email].should == [ "is invalid" ]
77
61
  end
78
62
 
63
+ describe "validating email with MX" do
64
+ subject { person_class_mx.new }
65
+
66
+ it "should pass when email domain has MX record" do
67
+ subject.email = 'john@gmail.com'
68
+ subject.valid?.should be_true
69
+ subject.errors[:email].should be_empty
70
+ end
71
+
72
+ it "should fail when email domain has no MX record" do
73
+ subject.email = 'john@subdomain.rubyonrails.org'
74
+ subject.valid?.should be_false
75
+ subject.errors[:email].should == errors
76
+ end
77
+
78
+ it "should fail when domain does not exists" do
79
+ subject.email = 'john@nonexistentdomain.abc'
80
+ subject.valid?.should be_false
81
+ subject.errors[:email].should == errors
82
+ end
83
+ end
84
+ end
85
+
86
+ describe "Translating in english" do
87
+ let!(:locale){ :en }
88
+ let!(:errors) { [ "is invalid" ] }
89
+ it_should_behave_like "Validating emails"
90
+ end
91
+
92
+ describe "Translating in french" do
93
+ let!(:locale){ :fr }
94
+
95
+ let!(:errors) { [ "est invalide" ] }
96
+ it_should_behave_like "Validating emails"
79
97
  end
80
- end
98
+
99
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: valid_email
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-12-09 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70131339816040 !ruby/object:Gem::Requirement
16
+ requirement: &70132350643040 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70131339816040
24
+ version_requirements: *70132350643040
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70131339815620 !ruby/object:Gem::Requirement
27
+ requirement: &70132350642620 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70131339815620
35
+ version_requirements: *70132350642620
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: mail
38
- requirement: &70131339815200 !ruby/object:Gem::Requirement
38
+ requirement: &70132350642200 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70131339815200
46
+ version_requirements: *70132350642200
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: activemodel
49
- requirement: &70131339814780 !ruby/object:Gem::Requirement
49
+ requirement: &70132350641780 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70131339814780
57
+ version_requirements: *70132350641780
58
58
  description: ActiveModel Validation for email
59
59
  email:
60
60
  - hery@rails-royce.org
@@ -67,6 +67,8 @@ files:
67
67
  - LICENSE
68
68
  - README.md
69
69
  - Rakefile
70
+ - config/locales/en.yml
71
+ - config/locales/fr.yml
70
72
  - lib/valid_email.rb
71
73
  - lib/valid_email/all.rb
72
74
  - lib/valid_email/email_validator.rb