email_address 0.1.19 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,35 +6,38 @@ class ApplicationRecord < ActiveRecord::Base
6
6
  self.abstract_class = true
7
7
  end
8
8
 
9
- dbfile = ENV['EMAIL_ADDRESS_TEST_DB'] || "/tmp/email_address.gem.db"
9
+ dbfile = ENV["EMAIL_ADDRESS_TEST_DB"] || "/tmp/email_address.gem.db"
10
10
  File.unlink(dbfile) if File.exist?(dbfile)
11
11
 
12
12
  # Connection: JRuby vs. MRI
13
- if RUBY_PLATFORM == 'java' # jruby
14
- require 'jdbc/sqlite3'
15
- require 'java'
16
- require 'activerecord-jdbcsqlite3-adapter'
17
- Jdbc::SQLite3.load_driver
18
- ActiveRecord::Base.establish_connection(
19
- :adapter => 'jdbc',
20
- :driver => "org.sqlite.JDBC",
21
- :url => "jdbc:sqlite:" + dbfile
22
- )
13
+ # Disabled JRuby checks... weird CI failures. Hopefully someone can help?
14
+ if RUBY_PLATFORM == "java" # jruby
15
+ # require "jdbc/sqlite3"
16
+ # require "java"
17
+ # require "activerecord-jdbcsqlite3-adapter"
18
+ # Jdbc::SQLite3.load_driver
19
+ # ActiveRecord::Base.establish_connection(
20
+ # adapter: "jdbc",
21
+ # driver: "org.sqlite.JDBC",
22
+ # url: "jdbc:sqlite:" + dbfile
23
+ # )
23
24
  else
24
- require 'sqlite3'
25
+ require "sqlite3"
25
26
  ActiveRecord::Base.establish_connection(
26
- :adapter => 'sqlite3',
27
- :database => dbfile
27
+ adapter: "sqlite3",
28
+ database: dbfile
28
29
  )
29
- end
30
30
 
31
- ApplicationRecord.connection.execute(
32
- "create table users ( email varchar, canonical_email varchar)")
31
+ # The following would be executed for both JRuby/MRI
32
+ ApplicationRecord.connection.execute(
33
+ "create table users ( email varchar, canonical_email varchar)"
34
+ )
33
35
 
34
- if defined?(ActiveRecord) && ::ActiveRecord::VERSION::MAJOR >= 5
35
- ActiveRecord::Type.register(:email_address, EmailAddress::EmailAddressType)
36
- ActiveRecord::Type.register(:canonical_email_address,
37
- EmailAddress::CanonicalEmailAddressType)
36
+ if defined?(ActiveRecord) && ::ActiveRecord::VERSION::MAJOR >= 5
37
+ ActiveRecord::Type.register(:email_address, EmailAddress::EmailAddressType)
38
+ ActiveRecord::Type.register(:canonical_email_address,
39
+ EmailAddress::CanonicalEmailAddressType)
40
+ end
38
41
  end
39
42
 
40
43
  ################################################################################
@@ -42,30 +45,28 @@ end
42
45
  ################################################################################
43
46
 
44
47
  class User < ApplicationRecord
45
-
46
48
  if defined?(ActiveRecord) && ::ActiveRecord::VERSION::MAJOR >= 5
47
49
  attribute :email, :email_address
48
50
  attribute :canonical_email, :canonical_email_address
49
51
  end
50
52
 
51
53
  validates_with EmailAddress::ActiveRecordValidator,
52
- fields: %i(email canonical_email)
54
+ fields: %i[email canonical_email]
53
55
 
54
56
  def email=(email_address)
55
57
  self[:canonical_email] = email_address
56
- self[:email] = email_address
58
+ self[:email] = email_address
57
59
  end
58
60
 
59
61
  def self.find_by_email(email)
60
- user = self.find_by(email: EmailAddress.normal(email))
61
- user ||= self.find_by(canonical_email: EmailAddress.canonical(email))
62
- user ||= self.find_by(canonical_email: EmailAddress.redacted(email))
62
+ user = find_by(email: EmailAddress.normal(email))
63
+ user ||= find_by(canonical_email: EmailAddress.canonical(email))
64
+ user ||= find_by(canonical_email: EmailAddress.redacted(email))
63
65
  user
64
66
  end
65
67
 
66
68
  def redact!
67
- self[:canonical_email] = EmailAddress.redact(self.canonical_email)
68
- self[:email] = self[:canonical_email]
69
+ self[:canonical_email] = EmailAddress.redact(canonical_email)
70
+ self[:email] = self[:canonical_email]
69
71
  end
70
-
71
72
  end
@@ -1,5 +1,4 @@
1
- #encoding: utf-8
2
- require_relative '../test_helper'
1
+ require_relative "../test_helper"
3
2
 
4
3
  class TestAddress < Minitest::Test
5
4
  def test_address
@@ -22,7 +21,7 @@ class TestAddress < Minitest::Test
22
21
  def test_host
23
22
  a = EmailAddress.new("User+tag@example.com")
24
23
  assert_equal "example.com", a.hostname
25
- #assert_equal :default, a.provider
24
+ # assert_equal :default, a.provider
26
25
  end
27
26
 
28
27
  # ADDRESS
@@ -34,7 +33,27 @@ class TestAddress < Minitest::Test
34
33
  assert_equal "{63a710569261a24b3766275b7000ce8d7b32e2f7}@example.com", a.redact
35
34
  assert_equal "{b58996c504c5638798eb6b511e6f49af}@example.com", a.redact(:md5)
36
35
  assert_equal "b58996c504c5638798eb6b511e6f49af", a.reference
37
- assert_equal "6bdd00c53645790ad9bbcb50caa93880", EmailAddress.reference("Gmail.User+tag@gmail.com")
36
+ assert_equal "6bdd00c53645790ad9bbcb50caa93880", EmailAddress.reference("Gmail.User+tag@gmail.com")
37
+ end
38
+
39
+ def test_sha1
40
+ a = EmailAddress.new("User+tag@example.com")
41
+ assert_equal "63a710569261a24b3766275b7000ce8d7b32e2f7", a.sha1
42
+ end
43
+
44
+ def test_sha1_with_secret
45
+ a = EmailAddress.new("User+tag@example.com", sha1_secret: "test-secret")
46
+ assert_equal "122df4ec3ce7121db6edc06a9e29eab39a7e8007", a.sha1
47
+ end
48
+
49
+ def test_sha256
50
+ a = EmailAddress.new("User+tag@example.com")
51
+ assert_equal "b4c9a289323b21a01c3e940f150eb9b8c542587f1abfd8f0e1cc1ffc5e475514", a.sha256
52
+ end
53
+
54
+ def test_sha256_with_secret
55
+ a = EmailAddress.new("User+tag@example.com", sha256_secret: "test-secret")
56
+ assert_equal "480899ff53ccd446cc123f0c5685869644af445e788f1b559054919674307a07", a.sha256
38
57
  end
39
58
 
40
59
  def test_google_hosted
@@ -44,23 +63,23 @@ class TestAddress < Minitest::Test
44
63
 
45
64
  # COMPARISON & MATCHING
46
65
  def test_compare
47
- a = ("User+tag@example.com")
48
- #e = EmailAddress.new("user@example.com")
66
+ a = "User+tag@example.com"
67
+ # e = EmailAddress.new("user@example.com")
49
68
  n = EmailAddress.new(a)
50
69
  c = EmailAddress.new_canonical(a)
51
- #r = EmailAddress.new_redacted(a)
70
+ # r = EmailAddress.new_redacted(a)
52
71
  assert_equal true, n == "user+tag@example.com"
53
- assert_equal true, n > "b@example.com"
72
+ assert_equal true, n > "b@example.com"
54
73
  assert_equal true, n.same_as?(c)
55
74
  assert_equal true, n.same_as?(a)
56
75
  end
57
76
 
58
77
  def test_matches
59
78
  a = EmailAddress.new("User+tag@gmail.com")
60
- assert_equal false, a.matches?('mail.com')
61
- assert_equal 'google', a.matches?('google')
62
- assert_equal 'user+tag@', a.matches?('user+tag@')
63
- assert_equal 'user*@gmail*', a.matches?('user*@gmail*')
79
+ assert_equal false, a.matches?("mail.com")
80
+ assert_equal "google", a.matches?("google")
81
+ assert_equal "user+tag@", a.matches?("user+tag@")
82
+ assert_equal "user*@gmail*", a.matches?("user*@gmail*")
64
83
  end
65
84
 
66
85
  def test_empty_address
@@ -74,18 +93,20 @@ class TestAddress < Minitest::Test
74
93
  # VALIDATION
75
94
  def test_valid
76
95
  assert EmailAddress.valid?("User+tag@example.com", host_validation: :a), "valid 1"
77
- assert ! EmailAddress.valid?("User%tag@example.com", host_validation: :a), "valid 2"
78
- assert EmailAddress.new("ɹᴉɐℲuǝll∀@ɹᴉɐℲuǝll∀.ws", local_encoding: :uncode, host_validation: :syntax ), "valid unicode"
96
+ assert !EmailAddress.valid?("User%tag@example.com", host_validation: :a), "valid 2"
97
+ assert EmailAddress.new("ɹᴉɐℲuǝll∀@ɹᴉɐℲuǝll∀.ws", local_encoding: :uncode, host_validation: :syntax), "valid unicode"
79
98
  end
80
99
 
81
100
  def test_localhost
82
101
  e = EmailAddress.new("User+tag.gmail.ws") # No domain means localhost
83
- assert_equal '', e.hostname
102
+ assert_equal "", e.hostname
84
103
  assert_equal false, e.valid? # localhost not allowed by default
85
104
  assert_equal EmailAddress.error("user1"), "Invalid Domain Name"
86
- assert_equal EmailAddress.error("user1", host_local:true), "This domain is not configured to accept email"
87
- assert_equal EmailAddress.error("user1@localhost", host_local:true), "This domain is not configured to accept email"
88
- assert_nil EmailAddress.error("user2@localhost", host_local:true, dns_lookup: :off, host_validation: :syntax)
105
+ assert_equal EmailAddress.error("user1", host_local: true), "This domain is not configured to accept email"
106
+ assert_equal EmailAddress.error("user1@localhost", host_local: true), "This domain is not configured to accept email"
107
+ assert_equal EmailAddress.error("user1@localhost", host_local: false, host_validation: :syntax), "localhost is not allowed for your domain name"
108
+ assert_equal EmailAddress.error("user1@localhost", host_local: false, dns_lookup: :off), "localhost is not allowed for your domain name"
109
+ assert_nil EmailAddress.error("user2@localhost", host_local: true, dns_lookup: :off, host_validation: :syntax)
89
110
  end
90
111
 
91
112
  def test_regexen
@@ -97,7 +118,7 @@ class TestAddress < Minitest::Test
97
118
  end
98
119
 
99
120
  def test_srs
100
- ea= "first.LAST+tag@gmail.com"
121
+ ea = "first.LAST+tag@gmail.com"
101
122
  e = EmailAddress.new(ea)
102
123
  s = e.srs("example.com")
103
124
  assert s.match(EmailAddress::Address::SRS_FORMAT_REGEX)
@@ -106,20 +127,20 @@ class TestAddress < Minitest::Test
106
127
 
107
128
  # Quick Regression tests for addresses that should have been valid (but fixed)
108
129
  def test_issues
109
- assert true, EmailAddress.valid?('test@jiff.com', dns_lookup: :mx) # #7
130
+ assert true, EmailAddress.valid?("test@jiff.com", dns_lookup: :mx) # #7
110
131
  assert true, EmailAddress.valid?("w.-asdf-_@hotmail.com") # #8
111
132
  assert true, EmailAddress.valid?("first_last@hotmail.com") # #8
112
133
  end
113
134
 
114
135
  def test_issue9
115
- assert ! EmailAddress.valid?('example.user@foo.')
116
- assert ! EmailAddress.valid?('ogog@sss.c')
117
- assert ! EmailAddress.valid?('example.user@foo.com/')
136
+ assert !EmailAddress.valid?("example.user@foo.")
137
+ assert !EmailAddress.valid?("ogog@sss.c")
138
+ assert !EmailAddress.valid?("example.user@foo.com/")
118
139
  end
119
140
 
120
141
  def test_relaxed_normal
121
- assert ! EmailAddress.new('a.c.m.e.-industries@foo.com').valid?
122
- assert true, EmailAddress.new('a.c.m.e.-industries@foo.com', local_format: :relaxed).valid?
142
+ assert !EmailAddress.new("a.c.m.e.-industries@foo.com").valid?
143
+ assert true, EmailAddress.new("a.c.m.e.-industries@foo.com", local_format: :relaxed).valid?
123
144
  end
124
145
 
125
146
  def test_nil_address
@@ -1,25 +1,25 @@
1
- require_relative '../test_helper'
1
+ require_relative "../test_helper"
2
2
 
3
3
  class TestConfig < MiniTest::Test
4
4
  def test_setting
5
- assert_equal :mx, EmailAddress::Config.setting(:dns_lookup)
5
+ assert_equal :mx, EmailAddress::Config.setting(:dns_lookup)
6
6
  assert_equal :off, EmailAddress::Config.setting(:dns_lookup, :off)
7
7
  assert_equal :off, EmailAddress::Config.setting(:dns_lookup)
8
8
  EmailAddress::Config.setting(:dns_lookup, :mx)
9
9
  end
10
10
 
11
11
  def test_configure
12
- assert_equal :mx, EmailAddress::Config.setting(:dns_lookup)
13
- assert_equal true, EmailAddress::Config.setting(:local_downcase)
14
- EmailAddress::Config.configure(local_downcase:false, dns_lookup: :off)
15
- assert_equal :off, EmailAddress::Config.setting(:dns_lookup)
12
+ assert_equal :mx, EmailAddress::Config.setting(:dns_lookup)
13
+ assert_equal true, EmailAddress::Config.setting(:local_downcase)
14
+ EmailAddress::Config.configure(local_downcase: false, dns_lookup: :off)
15
+ assert_equal :off, EmailAddress::Config.setting(:dns_lookup)
16
16
  assert_equal false, EmailAddress::Config.setting(:local_downcase)
17
- EmailAddress::Config.configure(local_downcase:true, dns_lookup: :mx)
17
+ EmailAddress::Config.configure(local_downcase: true, dns_lookup: :mx)
18
18
  end
19
19
 
20
20
  def test_provider
21
21
  assert_nil EmailAddress::Config.provider(:github)
22
- EmailAddress::Config.provider(:github, host_match: %w(github.com), local_format: :standard)
22
+ EmailAddress::Config.provider(:github, host_match: %w[github.com], local_format: :standard)
23
23
  assert_equal :standard, EmailAddress::Config.provider(:github)[:local_format]
24
24
  assert_equal :github, EmailAddress::Host.new("github.com").provider
25
25
  EmailAddress::Config.providers.delete(:github)
@@ -1,13 +1,12 @@
1
- #encoding: utf-8
2
- require_relative '../test_helper'
1
+ require_relative "../test_helper"
3
2
 
4
3
  class TestExchanger < MiniTest::Test
5
4
  def test_exchanger
6
5
  e = EmailAddress::Exchanger.new("gmail.com")
7
6
  assert_equal true, e.mxers.size > 1
8
7
  assert_equal :google, e.provider
9
- assert_equal 'google.com', e.domains.first
10
- assert_equal 'google.com', e.matches?("google.com")
8
+ assert_equal "google.com", e.domains.first
9
+ assert_equal "google.com", e.matches?("google.com")
11
10
  assert_equal false, e.matches?("fa00:1450:4013:c01::1a/16")
12
11
  assert_equal false, e.matches?("127.0.0.1/24")
13
12
  assert_equal true, e.mx_ips.size > 1
@@ -18,8 +17,8 @@ class TestExchanger < MiniTest::Test
18
17
  assert_equal 0, e.mxers.size
19
18
  end
20
19
 
21
- #assert_equal true, a.has_dns_a_record? # example.com has no MX'ers
22
- #def test_dns
20
+ # assert_equal true, a.has_dns_a_record? # example.com has no MX'ers
21
+ # def test_dns
23
22
  # good = EmailAddress::Exchanger.new("gmail.com")
24
23
  # bad = EmailAddress::Exchanger.new("exampldkeie4iufe.com")
25
24
  # assert_equal true, good.has_dns_a_record?
@@ -27,5 +26,5 @@ class TestExchanger < MiniTest::Test
27
26
  # assert_equal "gmail.com", good.dns_a_record.first
28
27
  # assert(/google.com\z/, good.mxers.first.first)
29
28
  # #assert_equal 'google.com', good.domains.first
30
- #end
29
+ # end
31
30
  end
@@ -110,7 +110,8 @@ class TestHost < MiniTest::Test
110
110
  end
111
111
 
112
112
  def test_hosted_service
113
- assert EmailAddress.valid?("test@jiff.com", dns_lookup: :mx)
113
+ # Is there a gmail-hosted domain that will continue to exist? Removing until then
114
+ # assert EmailAddress.valid?("test@jiff.com", dns_lookup: :mx)
114
115
  assert !EmailAddress.valid?("test@gmail.com", dns_lookup: :mx)
115
116
  end
116
117
 
@@ -1,22 +1,20 @@
1
- # encoding: UTF-8
2
- require_relative '../test_helper'
1
+ require_relative "../test_helper"
3
2
 
4
3
  class TestLocal < MiniTest::Test
5
-
6
4
  def test_valid_standard
7
5
  [ # Via https://en.wikipedia.org/wiki/Email_address
8
- %Q{prettyandsimple},
9
- %Q{very.common},
10
- %Q{disposable.style.email.with+symbol},
11
- %Q{other.email-with-dash},
12
- %Q{"much.more unusual"},
13
- %Q{"(comment)very.unusual.@.unusual.com"},
14
- %Q{#!$%&'*+-/=?^_`{}|~},
15
- %Q{" "},
16
- %Q{"very.(),:;<>[]\\".VERY.\\"very@\\ \\"very\\".unusual"},
17
- %Q{"()<>[]:,;@\\\"!#$%&'*+-/=?^_`{}| ~.a"},
18
- %Q{token." ".token},
19
- %Q{abc."defghi".xyz},
6
+ %(prettyandsimple),
7
+ %(very.common),
8
+ %(disposable.style.email.with+symbol),
9
+ %(other.email-with-dash),
10
+ %("much.more unusual"),
11
+ %{"(comment)very.unusual.@.unusual.com"},
12
+ %(#!$%&'*+-/=?^_`{}|~),
13
+ %(" "),
14
+ %{"very.(),:;<>[]\\".VERY.\\"very@\\ \\"very\\".unusual"},
15
+ %{"()<>[]:,;@\\\"!#$%&'*+-/=?^_`{}| ~.a"},
16
+ %(token." ".token),
17
+ %(abc."defghi".xyz)
20
18
  ].each do |local|
21
19
  assert EmailAddress::Local.new(local, local_fix: false).standard?, local
22
20
  end
@@ -24,15 +22,15 @@ class TestLocal < MiniTest::Test
24
22
 
25
23
  def test_invalid_standard
26
24
  [ # Via https://en.wikipedia.org/wiki/Email_address
27
- %Q{A@b@c},
28
- %Q{a"b(c)d,e:f;g<h>i[j\k]l},
29
- %Q{just"not"right},
30
- %Q{this is"not\allowed},
31
- %Q{this\ still\"not\\allowed},
32
- %Q{john..doe},
33
- %Q{ invalid},
34
- %Q{invalid },
35
- %Q{abc"defghi"xyz},
25
+ %(A@b@c),
26
+ %{a"b(c)d,e:f;g<h>i[j\k]l},
27
+ %(just"not"right),
28
+ %(this is"not\allowed),
29
+ %(this\ still\"not\\allowed),
30
+ %(john..doe),
31
+ %( invalid),
32
+ %(invalid ),
33
+ %(abc"defghi"xyz)
36
34
  ].each do |local|
37
35
  assert_equal false, EmailAddress::Local.new(local, local_fix: false).standard?, local
38
36
  end
@@ -46,22 +44,21 @@ class TestLocal < MiniTest::Test
46
44
  end
47
45
 
48
46
  def test_unicode
49
- assert ! EmailAddress::Local.new("üñîçøðé1", local_encoding: :ascii).standard?, "not üñîçøðé1"
47
+ assert !EmailAddress::Local.new("üñîçøðé1", local_encoding: :ascii).standard?, "not üñîçøðé1"
50
48
  assert EmailAddress::Local.new("üñîçøðé2", local_encoding: :unicode).standard?, "üñîçøðé2"
51
49
  assert EmailAddress::Local.new("test", local_encoding: :unicode).valid?, "unicode should include ascii"
52
- assert ! EmailAddress::Local.new("üñîçøðé3").valid?, "üñîçøðé3 valid"
50
+ assert !EmailAddress::Local.new("üñîçøðé3").valid?, "üñîçøðé3 valid"
53
51
  end
54
52
 
55
-
56
53
  def test_valid_conventional
57
- %w( first.last first First+Tag o'brien).each do |local|
54
+ %w[first.last first First+Tag o'brien].each do |local|
58
55
  assert EmailAddress::Local.new(local).conventional?, local
59
56
  end
60
57
  end
61
58
 
62
59
  def test_invalid_conventional
63
- (%w( first;.last +leading trailing+ o%brien) + ["first space"]).each do |local|
64
- assert ! EmailAddress::Local.new(local, local_fix:false).conventional?, local
60
+ (%w[first;.last +leading trailing+ o%brien] + ["first space"]).each do |local|
61
+ assert !EmailAddress::Local.new(local, local_fix: false).conventional?, local
65
62
  end
66
63
  end
67
64
 
@@ -72,8 +69,8 @@ class TestLocal < MiniTest::Test
72
69
 
73
70
  def test_format
74
71
  assert_equal :conventional, EmailAddress::Local.new("can1").format?
75
- assert_equal :standard, EmailAddress::Local.new(%Q{"can1"}).format?
76
- assert_equal "can1", EmailAddress::Local.new(%Q{"can1(commment)"}).format(:conventional)
72
+ assert_equal :standard, EmailAddress::Local.new(%("can1")).format?
73
+ assert_equal "can1", EmailAddress::Local.new(%{"can1(commment)"}).format(:conventional)
77
74
  end
78
75
 
79
76
  def test_redacted
@@ -84,9 +81,9 @@ class TestLocal < MiniTest::Test
84
81
 
85
82
  def test_matches
86
83
  a = EmailAddress.new("User+tag@gmail.com")
87
- assert_equal false, a.matches?('user')
88
- assert_equal false, a.matches?('user@')
89
- assert_equal 'user*@', a.matches?('user*@')
84
+ assert_equal false, a.matches?("user")
85
+ assert_equal false, a.matches?("user@")
86
+ assert_equal "user*@", a.matches?("user*@")
90
87
  end
91
88
 
92
89
  def test_munge
@@ -105,4 +102,11 @@ class TestLocal < MiniTest::Test
105
102
  assert EmailAddress.valid?("username_____@gmail.com")
106
103
  end
107
104
 
105
+ def test_tag_punctuation
106
+ assert EmailAddress.valid?("first.last+foo.bar@gmail.com")
107
+ end
108
+
109
+ def test_relaxed_tag
110
+ assert EmailAddress.valid? "foo+abc@example.com", host_validation: :syntax, local_format: :relaxed
111
+ end
108
112
  end
@@ -1,14 +1,11 @@
1
- #encoding: utf-8
2
- require_relative '../test_helper'
1
+ require_relative "../test_helper"
3
2
 
4
3
  class TestRewriter < Minitest::Test
5
-
6
4
  def test_srs
7
- ea= "first.LAST+tag@gmail.com"
5
+ ea = "first.LAST+tag@gmail.com"
8
6
  e = EmailAddress.new(ea)
9
7
  s = e.srs("example.com")
10
8
  assert s.match(EmailAddress::Address::SRS_FORMAT_REGEX)
11
9
  assert EmailAddress.new(s).to_s == e.to_s
12
10
  end
13
-
14
11
  end
@@ -1,5 +1,4 @@
1
- # encoding: UTF-8
2
- require_relative 'test_helper'
1
+ require_relative "test_helper"
3
2
 
4
3
  class TestAliasing < MiniTest::Test
5
4
  def setup
@@ -1,44 +1,41 @@
1
- # encoding: UTF-8
2
- require_relative 'test_helper'
1
+ require_relative "test_helper"
3
2
 
4
3
  class TestEmailAddress < MiniTest::Test
5
-
6
4
  def test_new
7
- a = EmailAddress.new('user@example.com')
8
- assert_equal 'user', a.local.to_s
9
- assert_equal 'example.com', a.host.to_s
5
+ a = EmailAddress.new("user@example.com")
6
+ assert_equal "user", a.local.to_s
7
+ assert_equal "example.com", a.host.to_s
10
8
  end
11
9
 
12
10
  def test_canonical
13
- assert_equal "firstlast@gmail.com", EmailAddress.canonical('First.Last+TAG@gmail.com')
14
- a = EmailAddress.new_canonical('First.Last+TAG@gmail.com')
15
- assert_equal 'firstlast', a.local.to_s
11
+ assert_equal "firstlast@gmail.com", EmailAddress.canonical("First.Last+TAG@gmail.com")
12
+ a = EmailAddress.new_canonical("First.Last+TAG@gmail.com")
13
+ assert_equal "firstlast", a.local.to_s
16
14
  end
17
15
 
18
16
  def test_normal
19
- assert_equal 'user+tag@gmail.com', EmailAddress.normal('USER+TAG@GMAIL.com')
17
+ assert_equal "user+tag@gmail.com", EmailAddress.normal("USER+TAG@GMAIL.com")
20
18
  end
21
19
 
22
20
  def test_valid
23
- assert_equal true, EmailAddress.valid?('user@yahoo.com')
24
- assert_equal true, EmailAddress.valid?('a@yahoo.com')
21
+ assert_equal true, EmailAddress.valid?("user@yahoo.com")
22
+ assert_equal true, EmailAddress.valid?("a@yahoo.com")
25
23
  end
26
24
 
27
25
  def test_matches
28
- assert_equal 'yahoo.', EmailAddress.matches?('user@yahoo.com', 'yahoo.')
26
+ assert_equal "yahoo.", EmailAddress.matches?("user@yahoo.com", "yahoo.")
29
27
  end
30
28
 
31
29
  def test_reference
32
- assert_equal 'dfeafc750cecde54f9a4775f5713bf01', EmailAddress.reference('user@yahoo.com')
30
+ assert_equal "dfeafc750cecde54f9a4775f5713bf01", EmailAddress.reference("user@yahoo.com")
33
31
  end
34
32
 
35
33
  def test_redact
36
- assert_equal '{e037b6c476357f34f92b8f35b25d179a4f573f1e}@yahoo.com', EmailAddress.redact('user@yahoo.com')
34
+ assert_equal "{e037b6c476357f34f92b8f35b25d179a4f573f1e}@yahoo.com", EmailAddress.redact("user@yahoo.com")
37
35
  end
38
36
 
39
37
  def test_cases
40
- %w( miles.o'brien@yahoo.com first.last@gmail.com a-b.c_d+e@f.gx
41
- ).each do |address|
38
+ %w[miles.o'brien@yahoo.com first.last@gmail.com a-b.c_d+e@f.gx].each do |address|
42
39
  assert EmailAddress.valid?(address, host_validation: :syntax), "valid?(#{address})"
43
40
  end
44
41
  end
@@ -47,5 +44,4 @@ class TestEmailAddress < MiniTest::Test
47
44
  assert_equal "", EmailAddress.normal("")
48
45
  assert_equal "", EmailAddress.normal(" ")
49
46
  end
50
-
51
47
  end
data/test/test_helper.rb CHANGED
@@ -1,11 +1,12 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
2
2
 
3
- require 'simplecov'
3
+ require "pry"
4
+ require "simplecov"
4
5
  SimpleCov.start
5
6
 
6
- require 'active_record'
7
- require 'rubygems'
8
- require 'minitest/autorun'
9
- require 'minitest/unit'
10
- require 'minitest/pride'
11
- require 'email_address'
7
+ require "active_record"
8
+ require "rubygems"
9
+ require "minitest/autorun"
10
+ require "minitest/unit"
11
+ require "minitest/pride"
12
+ require "email_address"