validates_email_format_of 1.5.3 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ module ValidatesEmailFormatOf
2
+ class Railtie < Rails::Railtie
3
+ initializer 'validates_email_format_of.load_i18n_locales' do |app|
4
+ ValidatesEmailFormatOf::load_i18n_locales
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ require "validates_email_format_of"
2
+
3
+ RSpec::Matchers.define :validate_email_format_of do |attribute|
4
+ match do
5
+ actual_class_name = subject.is_a?(Class) ? subject : subject.class
6
+ actual = actual_class_name.new
7
+ actual.send(:"#{attribute}=", "invalid@example.")
8
+ expect(actual).to be_invalid
9
+ @expected_message ||= ValidatesEmailFormatOf.default_message
10
+ expect(actual.errors.messages[attribute.to_sym]).to include(@expected_message)
11
+ end
12
+ chain :with_message do |message|
13
+ @expected_message = message
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module ValidatesEmailFormatOf
2
+ VERSION = '1.6.0'
3
+ end
data/rakefile.rb CHANGED
@@ -1,27 +1 @@
1
- require 'rake'
2
- require 'rake/testtask'
3
- require 'rake/rdoctask'
4
-
5
- desc 'Default: run unit tests.'
6
- task :default => [:clean_log, :test]
7
-
8
- desc 'Remove the old log file'
9
- task :clean_log do
10
- "rm -f #{File.dirname(__FILE__)}/test/debug.log" if File.exists?(File.dirname(__FILE__) + '/test/debug.log')
11
- end
12
-
13
- desc 'Test the validates_email_format_of plugin.'
14
- Rake::TestTask.new(:test) do |t|
15
- t.libs << 'lib'
16
- t.pattern = FileList['test/**/*_test.rb']
17
- t.verbose = true
18
- end
19
-
20
- desc 'Generate documentation for the validates_email_format_of plugin and gem.'
21
- Rake::RDocTask.new(:rdoc) do |rdoc|
22
- rdoc.rdoc_dir = 'rdoc'
23
- rdoc.title = 'validates_email_format_of plugin and gem'
24
- rdoc.options << '--line-numbers --inline-source'
25
- rdoc.rdoc_files.include('README.rdoc')
26
- rdoc.rdoc_files.include('lib/**/*.rb')
27
- end
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,14 @@
1
+ require "#{File.expand_path(File.dirname(__FILE__))}/spec_helper"
2
+ if defined?(ActiveModel)
3
+ require "validates_email_format_of/rspec_matcher"
4
+
5
+ class Person
6
+ attr_accessor :email_address
7
+ include ::ActiveModel::Validations
8
+ validates_email_format_of :email_address
9
+ end
10
+
11
+ describe Person do
12
+ it { should validate_email_format_of(:email_address) }
13
+ end
14
+ end
@@ -0,0 +1,29 @@
1
+ require 'active_model' if Gem.loaded_specs.keys.include?('activemodel')
2
+
3
+ RSpec::Matchers.define :have_errors_on_email do
4
+ match do |actual|
5
+ expect(actual).not_to be_nil, "#{actual} should not be nil"
6
+ expect(actual).not_to be_empty, "#{actual} should not be empty"
7
+ expect(actual.size).to eq(@reasons.size), "#{actual} should have #{@reasons.size} elements"
8
+ @reasons.each do |reason|
9
+ reason = "#{"Email " if defined?(ActiveModel)}#{reason}"
10
+ expect(actual).to include(reason), "#{actual} should contain #{reason}"
11
+ end
12
+ end
13
+ chain :because do |reason|
14
+ (@reasons ||= []) << reason
15
+ end
16
+ chain :and_because do |reason|
17
+ (@reasons ||= []) << reason
18
+ end
19
+ match_when_negated do |actual|
20
+ expect(actual).to (defined?(ActiveModel) ? be_empty : be_nil)
21
+ end
22
+ end
23
+
24
+ RSpec.configure do |config|
25
+ config.before(:suite) do
26
+ ValidatesEmailFormatOf.load_i18n_locales
27
+ I18n.enforce_available_locales = false
28
+ end
29
+ end
@@ -0,0 +1,308 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require "#{File.expand_path(File.dirname(__FILE__))}/spec_helper"
3
+ require "validates_email_format_of"
4
+
5
+ describe ValidatesEmailFormatOf do
6
+ subject do |example|
7
+ if defined?(ActiveModel)
8
+ user = Class.new do
9
+ def initialize(email)
10
+ @email = email.freeze
11
+ end
12
+ attr_reader :email
13
+ include ActiveModel::Validations
14
+ validates_email_format_of :email, example.example_group_instance.options
15
+ end
16
+ example.example_group_instance.class::User = user
17
+ user.new(example.example_group_instance.email).tap(&:valid?).errors.full_messages
18
+ else
19
+ ValidatesEmailFormatOf::validate_email_format(email.freeze, options)
20
+ end
21
+ end
22
+ let(:options) { {} }
23
+ let(:email) { |example| example.example_group.description }
24
+
25
+ shared_examples_for :all_specs do
26
+ [
27
+ 'valid@example.com',
28
+ 'Valid@test.example.com',
29
+ 'valid+valid123@test.example.com',
30
+ 'valid_valid123@test.example.com',
31
+ 'valid-valid+123@test.example.co.uk',
32
+ 'valid-valid+1.23@test.example.com.au',
33
+ 'valid@example.co.uk',
34
+ 'v@example.com',
35
+ 'valid@example.ca',
36
+ 'valid_@example.com',
37
+ 'valid123.456@example.org',
38
+ 'valid123.456@example.travel',
39
+ 'valid123.456@example.museum',
40
+ 'valid@example.mobi',
41
+ 'valid@example.info',
42
+ 'valid-@example.com',
43
+ 'fake@p-t.k12.ok.us',
44
+ # allow single character domain parts
45
+ 'valid@mail.x.example.com',
46
+ 'valid@x.com',
47
+ 'valid@example.w-dash.sch.uk',
48
+ # from RFC 3696, page 6
49
+ 'customer/department=shipping@example.com',
50
+ '$A12345@example.com',
51
+ '!def!xyz%abc@example.com',
52
+ '_somename@example.com',
53
+ # apostrophes
54
+ "test'test@example.com",
55
+ # international domain names
56
+ 'test@xn--bcher-kva.ch',
57
+ 'test@example.xn--0zwm56d',
58
+ 'test@192.192.192.1',
59
+ # Allow quoted characters. Valid according to http://www.rfc-editor.org/errata_search.php?rfc=3696
60
+ '"Abc\@def"@example.com',
61
+ '"Fred\ Bloggs"@example.com',
62
+ '"Joe.\\Blow"@example.com',
63
+ # Balanced quoted characters
64
+ %!"example\\\\\\""@example.com!,
65
+ %!"example\\\\"@example.com!
66
+ ].each do |address|
67
+ describe address do
68
+ it { should_not have_errors_on_email }
69
+ end
70
+ end
71
+
72
+ [
73
+ 'no_at_symbol',
74
+ 'invalid@example-com',
75
+ # period can not start local part
76
+ '.invalid@example.com',
77
+ # period can not end local part
78
+ 'invalid.@example.com',
79
+ # period can not appear twice consecutively in local part
80
+ 'invali..d@example.com',
81
+ # should not allow underscores in domain names
82
+ 'invalid@ex_mple.com',
83
+ 'invalid@e..example.com',
84
+ 'invalid@p-t..example.com',
85
+ 'invalid@example.com.',
86
+ 'invalid@example.com_',
87
+ 'invalid@example.com-',
88
+ 'invalid-example.com',
89
+ 'invalid@example.b#r.com',
90
+ 'invalid@example.c',
91
+ 'invali d@example.com',
92
+ # TLD can not be only numeric
93
+ 'invalid@example.123',
94
+ # unclosed quote
95
+ "\"a-17180061943-10618354-1993365053@example.com",
96
+ # too many special chars used to cause the regexp to hang
97
+ "-+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++@foo",
98
+ 'invalidexample.com',
99
+ # should not allow special chars after a period in the domain
100
+ 'local@sub.)domain.com',
101
+ 'local@sub.#domain.com',
102
+ # one at a time
103
+ "foo@example.com\nexample@gmail.com",
104
+ 'invalid@example.',
105
+ "\"foo\\\\\"\"@bar.com",
106
+ "foo@mail.com\r\nfoo@mail.com",
107
+ '@example.com',
108
+ 'foo@',
109
+ 'foo',
110
+ 'Iñtërnâtiônàlizætiøn@hasnt.happened.to.email',
111
+ # Escaped characters with quotes. From http://tools.ietf.org/html/rfc3696, page 5. Corrected in http://www.rfc-editor.org/errata_search.php?rfc=3696
112
+ 'Fred\ Bloggs_@example.com',
113
+ 'Abc\@def+@example.com',
114
+ 'Joe.\\Blow@example.com',
115
+ # Unbalanced quoted characters
116
+ %!"example\\\\""example.com!
117
+ ].each do |address|
118
+ describe address do
119
+ it { should have_errors_on_email.because("does not appear to be a valid e-mail address") }
120
+ end
121
+ end
122
+
123
+ describe do
124
+ shared_examples_for :local_length_limit do |limit|
125
+ describe "#{'a' * limit}@example.com" do
126
+ it { should_not have_errors_on_email }
127
+ end
128
+ describe "#{'a' * (limit + 1)}@example.com" do
129
+ it { should have_errors_on_email.because("does not appear to be a valid e-mail address") }
130
+ end
131
+ end
132
+ describe "when using default" do
133
+ it_should_behave_like :local_length_limit, 64
134
+ end
135
+ describe "when overriding defaults" do
136
+ let(:options) { { :local_length => 20 } }
137
+ it_should_behave_like :local_length_limit, 20
138
+ end
139
+ end
140
+ describe do
141
+ shared_examples_for :domain_length_limit do |limit|
142
+ describe "user@#{'a' * (limit - 4)}.com" do
143
+ it { should_not have_errors_on_email }
144
+ end
145
+ describe "user@#{'a' * (limit - 3)}.com" do
146
+ it { should have_errors_on_email.because("does not appear to be a valid e-mail address") }
147
+ end
148
+ end
149
+ describe "when using default" do
150
+ it_should_behave_like :domain_length_limit, 255
151
+ end
152
+ describe "when overriding defaults" do
153
+ let(:options) { { :domain_length => 100 } }
154
+ it_should_behave_like :domain_length_limit, 100
155
+ end
156
+ end
157
+
158
+ describe "custom error messages" do
159
+ describe 'invalid@example.' do
160
+ let(:options) { { :message => "just because I don't like you" } }
161
+ it { should have_errors_on_email.because("just because I don't like you") }
162
+ end
163
+ end
164
+
165
+ describe "mx record" do
166
+ domain = "stubbed.com"
167
+ email = "valid@#{domain}"
168
+ describe "when testing" do
169
+ let(:dns) { double(Resolv::DNS) }
170
+ let(:mx_record) { [double] }
171
+ let(:a_record) { [double] }
172
+ before(:each) do
173
+ allow(Resolv::DNS).to receive(:open).and_yield(dns)
174
+ allow(dns).to receive(:getresources).with(domain, Resolv::DNS::Resource::IN::MX).once.and_return(mx_record)
175
+ allow(dns).to receive(:getresources).with(domain, Resolv::DNS::Resource::IN::A).once.and_return(a_record)
176
+ end
177
+ let(:options) { { :check_mx => true } }
178
+ describe "and only an mx record is found" do
179
+ let(:a_record) { [] }
180
+ describe email do
181
+ it { should_not have_errors_on_email }
182
+ end
183
+ end
184
+ describe "and only an a record is found" do
185
+ let(:mx_record) { [] }
186
+ describe email do
187
+ it { should_not have_errors_on_email }
188
+ end
189
+ end
190
+ describe "and both an mx record and an a record are found" do
191
+ describe email do
192
+ it { should_not have_errors_on_email }
193
+ end
194
+ end
195
+ describe "and neither an mx record nor an a record is found" do
196
+ let(:a_record) { [] }
197
+ let(:mx_record) { [] }
198
+ describe email do
199
+ it { should have_errors_on_email.because("is not routable") }
200
+ end
201
+ describe "with a custom error message" do
202
+ let(:options) { { :check_mx => true, :mx_message => "There ain't no such domain!" } }
203
+ describe email do
204
+ it { should have_errors_on_email.because("There ain't no such domain!") }
205
+ end
206
+ end
207
+ describe "i18n" do
208
+ before(:each) { allow(I18n.config).to receive(:locale).and_return(locale) }
209
+ describe "present locale" do
210
+ let(:locale) { :pl }
211
+ describe email do
212
+ it { should have_errors_on_email.because("jest nieosiągalny") }
213
+ end
214
+ end
215
+ describe email do
216
+ let(:locale) { :ir }
217
+ describe email do
218
+ it { should have_errors_on_email.because("is not routable") }
219
+ end
220
+ end
221
+ end
222
+ unless defined?(ActiveModel)
223
+ describe "without i18n" do
224
+ before(:each) { hide_const("I18n") }
225
+ describe email do
226
+ it { should have_errors_on_email.because("is not routable") }
227
+ end
228
+ end
229
+ end
230
+ end
231
+ end
232
+ describe "when not testing" do
233
+ before(:each) { allow(Resolv::DNS).to receive(:open).never }
234
+ describe "by default" do
235
+ describe email do
236
+ it { should_not have_errors_on_email }
237
+ end
238
+ end
239
+ describe "explicitly" do
240
+ describe email do
241
+ let(:options) { { :check_mx => false } }
242
+ it { should_not have_errors_on_email }
243
+ end
244
+ end
245
+ end
246
+ describe "without mocks" do
247
+ describe email do
248
+ let(:options) { { :check_mx => true } }
249
+ it { should_not have_errors_on_email }
250
+ end
251
+ end
252
+ end
253
+
254
+ describe "custom regex" do
255
+ let(:options) { { :with => /[0-9]+\@[0-9]+/ } }
256
+ describe '012345@789' do
257
+ it { should_not have_errors_on_email }
258
+ end
259
+ describe 'valid@example.com' do
260
+ it { should have_errors_on_email.because("does not appear to be a valid e-mail address") }
261
+ end
262
+ end
263
+
264
+ describe "i18n" do
265
+ before(:each) { allow(I18n.config).to receive(:locale).and_return(locale) }
266
+ describe "present locale" do
267
+ let(:locale) { :pl }
268
+ describe "invalid@exmaple." do
269
+ it { should have_errors_on_email.because("nieprawidłowy adres e-mail") }
270
+ end
271
+ end
272
+ describe "missing locale" do
273
+ let(:locale) { :ir }
274
+ describe "invalid@exmaple." do
275
+ it { should have_errors_on_email.because("does not appear to be valid") }
276
+ end
277
+ end
278
+ end
279
+ unless defined?(ActiveModel)
280
+ describe "without i18n" do
281
+ before(:each) { hide_const("I18n") }
282
+ describe "invalid@exmaple." do
283
+ it { should have_errors_on_email.because("does not appear to be valid") }
284
+ end
285
+ end
286
+ end
287
+ end
288
+ it_should_behave_like :all_specs
289
+
290
+ if defined?(ActiveModel)
291
+ describe "shorthand ActiveModel validation" do
292
+ subject do |example|
293
+ user = Class.new do
294
+ def initialize(email)
295
+ @email = email.freeze
296
+ end
297
+ attr_reader :email
298
+ include ActiveModel::Validations
299
+ validates :email, :email_format => example.example_group_instance.options
300
+ end
301
+ example.example_group_instance.class::User = user
302
+ user.new(example.example_group_instance.email).tap(&:valid?).errors.full_messages
303
+ end
304
+
305
+ it_should_behave_like :all_specs
306
+ end
307
+ end
308
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.unshift File.expand_path('../lib', __FILE__)
3
+ require 'validates_email_format_of/version'
4
+
5
+ spec = Gem::Specification.new do |s|
6
+ s.name = 'validates_email_format_of'
7
+ s.version = ValidatesEmailFormatOf::VERSION
8
+ s.summary = 'Validate e-mail addresses against RFC 2822 and RFC 3696.'
9
+ s.description = s.summary
10
+ s.authors = ['Alex Dunae', 'Isaac Betesh']
11
+ s.email = ['code@dunae.ca', 'iybetesh@gmail.com']
12
+ s.homepage = 'https://github.com/validates-email-format-of/validates_email_format_of'
13
+ s.license = 'MIT'
14
+ s.test_files = s.files.grep(%r{^test/})
15
+ s.files = `git ls-files`.split($/)
16
+ s.require_paths = ['lib']
17
+
18
+ s.add_dependency 'i18n'
19
+ s.add_development_dependency 'bundler'
20
+ s.add_development_dependency 'rspec'
21
+ end
metadata CHANGED
@@ -1,87 +1,113 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validates_email_format_of
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.3
5
- prerelease:
4
+ version: 1.6.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Alex Dunae
8
+ - Isaac Betesh
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-12 00:00:00.000000000Z
12
+ date: 2014-08-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: sqlite3
16
- requirement: &2160409580 !ruby/object:Gem::Requirement
17
- none: false
15
+ name: i18n
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ! '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ! '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
18
31
  requirements:
19
32
  - - ! '>='
20
33
  - !ruby/object:Gem::Version
21
34
  version: '0'
22
35
  type: :development
23
36
  prerelease: false
24
- version_requirements: *2160409580
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
25
42
  - !ruby/object:Gem::Dependency
26
- name: activerecord
27
- requirement: &2160407040 !ruby/object:Gem::Requirement
28
- none: false
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
29
45
  requirements:
30
46
  - - ! '>='
31
47
  - !ruby/object:Gem::Version
32
48
  version: '0'
33
49
  type: :development
34
50
  prerelease: false
35
- version_requirements: *2160407040
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
36
56
  description: Validate e-mail addresses against RFC 2822 and RFC 3696.
37
- email: code@dunae.ca
57
+ email:
58
+ - code@dunae.ca
59
+ - iybetesh@gmail.com
38
60
  executables: []
39
61
  extensions: []
40
- extra_rdoc_files:
41
- - README.rdoc
42
- - MIT-LICENSE
62
+ extra_rdoc_files: []
43
63
  files:
64
+ - .gitignore
65
+ - .rspec
66
+ - .travis.yml
67
+ - Gemfile
44
68
  - MIT-LICENSE
45
- - init.rb
46
- - rakefile.rb
47
69
  - README.rdoc
70
+ - config/locales/en.yml
71
+ - config/locales/pl.yml
72
+ - gemfiles/Gemfile.active_model_2_1
73
+ - gemfiles/Gemfile.active_model_3_0
74
+ - gemfiles/Gemfile.active_model_3_1
75
+ - gemfiles/Gemfile.active_model_3_2
76
+ - gemfiles/Gemfile.active_model_3_3
77
+ - gemfiles/Gemfile.active_model_4_0
78
+ - gemfiles/Gemfile.active_model_4_1
48
79
  - lib/validates_email_format_of.rb
49
- - test/fixtures/person.rb
50
- - test/schema.rb
51
- - test/test_helper.rb
52
- - test/validates_email_format_of_test.rb
53
- - test/database.yml
54
- - test/fixtures/people.yml
55
- homepage: https://github.com/alexdunae/validates_email_format_of
56
- licenses: []
80
+ - lib/validates_email_format_of/active_model.rb
81
+ - lib/validates_email_format_of/railtie.rb
82
+ - lib/validates_email_format_of/rspec_matcher.rb
83
+ - lib/validates_email_format_of/version.rb
84
+ - rakefile.rb
85
+ - spec/rspec_matcher_spec.rb
86
+ - spec/spec_helper.rb
87
+ - spec/validates_email_format_of_spec.rb
88
+ - validates_email_format_of.gemspec
89
+ homepage: https://github.com/validates-email-format-of/validates_email_format_of
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
57
93
  post_install_message:
58
- rdoc_options:
59
- - --title
60
- - validates_email_format_of
94
+ rdoc_options: []
61
95
  require_paths:
62
96
  - lib
63
97
  required_ruby_version: !ruby/object:Gem::Requirement
64
- none: false
65
98
  requirements:
66
99
  - - ! '>='
67
100
  - !ruby/object:Gem::Version
68
101
  version: '0'
69
102
  required_rubygems_version: !ruby/object:Gem::Requirement
70
- none: false
71
103
  requirements:
72
104
  - - ! '>='
73
105
  - !ruby/object:Gem::Version
74
106
  version: '0'
75
107
  requirements: []
76
108
  rubyforge_project:
77
- rubygems_version: 1.8.10
109
+ rubygems_version: 2.1.5
78
110
  signing_key:
79
- specification_version: 3
111
+ specification_version: 4
80
112
  summary: Validate e-mail addresses against RFC 2822 and RFC 3696.
81
- test_files:
82
- - test/fixtures/person.rb
83
- - test/schema.rb
84
- - test/test_helper.rb
85
- - test/validates_email_format_of_test.rb
86
- - test/database.yml
87
- - test/fixtures/people.yml
113
+ test_files: []