email_format 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1572f05a8b9ebf1fa07bd0066312b822372f44cb
4
- data.tar.gz: 559b63ccc610d4cff6cb55555f75c9ea28c91db5
3
+ metadata.gz: c31c4d88f2a0645a013a802257d3babbc90f0e2b
4
+ data.tar.gz: be4d1fd92dc9bf36dfa4522ae65e6156fff2d5ee
5
5
  SHA512:
6
- metadata.gz: 2ea307ac3967b10f1486e1ce015abe888680b83d62a8ea5e00a701f5637d3d0e2df376a1fa43e6c0693499c707c7f9b40cb3d2b5488fa244d830d247bd47b9f1
7
- data.tar.gz: 633d4f45495ecd04e2f12187e0b6f3d8f9afb60757dc9607d34a1dff089be7f62d58921e935d5433cf1cf7817eb8496dfd02a57a5c8e2198d1ed615e969015f9
6
+ metadata.gz: bfacbc6d8596a86ea00d9316dd68774b4d3d149d73890ef09dd955c1658053d04f9db4105b02a5a6c8767cbd9c93df6b3b307e97d296632eda9ad4e4758819a7
7
+ data.tar.gz: c2d7be4a4014895dfbf7e43946742788ef55813a9d4ab0210c2a2d8cbb3affe8072b66599157431c76910b0e0fbf4370b70867bedac18ea9aef800a2ccc1fdf0
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -1,9 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
- - 2.0.0
5
- - 2.1.0
6
-
7
- notifications:
8
- email:
9
- - johnotander@gmail.com
3
+ - '1.9'
4
+ - '2'
5
+
6
+ before_install:
7
+ - gem install bundler
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 johnotander
1
+ Copyright (c) 2013-2015 johnotander
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -22,7 +22,7 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- ### `EmailFormat` Module
25
+ ### EmailFormat Module
26
26
 
27
27
  There's a `valid?` method in the `EmailFormat` module that accepts an email as an argument:
28
28
 
@@ -32,7 +32,7 @@ EmailFormat.valid?('invalid_email') # => false
32
32
  EmailFormat.valid?('valid@email.com') # => true
33
33
  ```
34
34
 
35
- ### `ActiveModel::Validations`
35
+ ### ActiveModel::Validations
36
36
 
37
37
  Using it is as simple as using the `validates` keyword in your model:
38
38
 
@@ -55,6 +55,20 @@ User.new('valid@email.com').valid? # => true
55
55
  User.new('invalid_email@@').valid? # => false
56
56
  ```
57
57
 
58
+ By default, `email_format` is pretty relaxed, but there is a `strict` mode
59
+
60
+ ```ruby
61
+ class User < ActiveRecord::Base
62
+
63
+ # ...
64
+
65
+ validates :email, email_format: { strict: true }
66
+
67
+ # ...
68
+
69
+ end
70
+ ```
71
+
58
72
  Also, the model in question doesn't need to inherit from ActiveRecord::Base, you only need to `include ActiveModel::Validations` in your class:
59
73
 
60
74
  ```ruby
data/Rakefile CHANGED
@@ -1,4 +1,4 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
2
  require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new
@@ -4,24 +4,24 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'email_format/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "email_format"
7
+ spec.name = 'email_format'
8
8
  spec.version = EmailFormat::VERSION
9
- spec.authors = ["johnotander"]
10
- spec.email = ["johnotander@gmail.com"]
9
+ spec.authors = ['johnotander']
10
+ spec.email = ['johnotander@gmail.com']
11
11
  spec.description = %q{Validates the email format.}
12
12
  spec.summary = %q{Validates the email format with the email_regex gem.}
13
- spec.homepage = "https://github.com/johnotander/email_format"
14
- spec.license = "MIT"
13
+ spec.homepage = 'https://github.com/johnotander/email_format'
14
+ spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_development_dependency "rspec"
22
- spec.add_development_dependency "bundler", "~> 1.3"
23
- spec.add_development_dependency "rake"
21
+ spec.add_development_dependency 'rspec'
22
+ spec.add_development_dependency 'bundler', '> 1.10'
23
+ spec.add_development_dependency 'rake'
24
24
 
25
- spec.add_dependency "activemodel"
26
- spec.add_dependency "email_regex"
25
+ spec.add_dependency 'activemodel'
26
+ spec.add_dependency 'email_regex'
27
27
  end
@@ -1,10 +1,13 @@
1
- require "email_regex"
2
- require "email_format/version"
3
- require "email_format/email_format_validator"
1
+ require 'email_regex'
2
+ require 'email_format/version'
3
+ require 'email_format/email_format_validator'
4
4
 
5
5
  module EmailFormat
6
-
7
- def self.valid?(email)
8
- !!(email =~ EmailRegex::EMAIL_ADDRESS_REGEX)
6
+ def self.valid?(email, strict)
7
+ if strict
8
+ !!(email =~ EmailRegex::EMAIL_ADDRESS_REGEX)
9
+ else
10
+ !!(email =~ /^[\S&&[^@]]+@[\S&&[^@]]+$/)
11
+ end
9
12
  end
10
13
  end
@@ -1,7 +1,6 @@
1
1
  class EmailFormatValidator < ActiveModel::EachValidator
2
2
  def validate_each(record, attribute, value)
3
- unless EmailFormat.valid?(value)
4
- record.errors[attribute] << (options[:message] || "is invalid")
5
- end
3
+ return if EmailFormat.valid?(value, options[:strict])
4
+ record.errors[attribute] << (options[:message] || 'is invalid')
6
5
  end
7
6
  end
@@ -1,3 +1,3 @@
1
1
  module EmailFormat
2
- VERSION = "0.0.2"
2
+ VERSION = '1.0.0'
3
3
  end
@@ -1,47 +1,84 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe EmailFormatValidator do
4
-
5
4
  let(:fake_model) { FakeModel.new }
5
+ let(:fake_model_strict) { FakeModelStrict.new }
6
+
7
+ describe 'valid emails' do
8
+ context 'with strict email requirements' do
9
+ let(:valid_emails) { %w(valid@email.com another.valid@email.email.net) }
6
10
 
7
- context "with valid emails" do
11
+ it 'should be happy' do
12
+ valid_emails.each do |email|
13
+ fake_model_strict.email = email
14
+ expect(fake_model_strict.valid?).to be_truthy
15
+ end
16
+ end
17
+ end
8
18
 
9
- let(:valid_emails) { %w(valid@email.com another.valid@email.email.net) }
19
+ context 'with non strict requirements' do
20
+ let(:valid_emails) do
21
+ %w(valid@email.com
22
+ another.valid@email.email.net
23
+ valid@a
24
+ a@vaild
25
+ a@a)
26
+ end
10
27
 
11
- it "should be happy" do
12
- valid_emails.each do |email|
13
- fake_model.email = email
14
- expect(fake_model.valid?).to be_true
28
+ it 'should be happy' do
29
+ valid_emails.each do |email|
30
+ fake_model.email = email
31
+ expect(fake_model.valid?).to be_truthy
32
+ end
15
33
  end
16
34
  end
17
35
  end
18
36
 
19
- context "with invalid emails" do
37
+ describe 'invalid emails' do
38
+ context 'with strict requirements' do
39
+ let(:invalid_emails) do
40
+ %w(invalid_email@
41
+ another_invalid_email@@email.email
42
+ invalid
43
+ bad@email@here
44
+ @bad_email
45
+ another@bad,email)
46
+ end
20
47
 
21
- let(:invalid_emails) { %w(invalid_email@
22
- another_invalid_email@@email.email
23
- invalid
24
- bad@email@here
25
- @bad_email
26
- another@bad,email) }
48
+ it 'should not be happy' do
49
+ invalid_emails.each do |email|
50
+ fake_model_strict.email = email
51
+ expect(fake_model_strict.valid?).to be_falsey
52
+ end
53
+ end
54
+ end
27
55
 
28
- it "shouldn't be happy" do
29
- invalid_emails.each do |email|
30
- fake_model.email = email
31
- expect(fake_model.valid?).to be_false
56
+ context 'with non strict requirements' do
57
+ let(:invalid_emails) do
58
+ %w(invalid_email@
59
+ another_invalid_email@@email.email
60
+ invalid
61
+ bad@email@here
62
+ @bad_email)
63
+ end
64
+
65
+ it 'should not be happy' do
66
+ invalid_emails.each do |email|
67
+ fake_model.email = email
68
+ expect(fake_model.valid?).to be_falsey
69
+ end
32
70
  end
33
71
  end
34
72
  end
35
73
 
36
- context "with allow_blank: true" do
37
-
38
- let(:fake_model) { FakeModelWithBlankEmail.new }
74
+ context 'with allow_blank: true' do
75
+ let(:fake_model_strict) { FakeModelWithBlankEmail.new }
39
76
  let(:blank_emails) { ['', nil, ' '] }
40
77
 
41
- it "should allow blank emails" do
78
+ it 'should allow blank emails' do
42
79
  blank_emails.each do |blank_email|
43
- fake_model.email = blank_email
44
- expect(fake_model.valid?).to be_true
80
+ fake_model_strict.email = blank_email
81
+ expect(fake_model_strict.valid?).to be_truthy
45
82
  end
46
83
  end
47
84
  end
@@ -4,10 +4,6 @@ require 'rspec'
4
4
  require 'active_model'
5
5
  require 'email_format'
6
6
 
7
- RSpec.configure do |config|
8
- config.color_enabled = true
9
- end
10
-
11
7
  class FakeModel
12
8
  include ActiveModel::Validations
13
9
 
@@ -16,6 +12,14 @@ class FakeModel
16
12
  validates :email, email_format: true
17
13
  end
18
14
 
15
+ class FakeModelStrict
16
+ include ActiveModel::Validations
17
+
18
+ attr_accessor :email
19
+
20
+ validates :email, email_format: { strict: true }
21
+ end
22
+
19
23
  class FakeModelWithBlankEmail
20
24
  include ActiveModel::Validations
21
25
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: email_format
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - johnotander
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-05 00:00:00.000000000 Z
11
+ date: 2016-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.3'
33
+ version: '1.10'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.3'
40
+ version: '1.10'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -88,6 +88,7 @@ extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
90
  - ".gitignore"
91
+ - ".rspec"
91
92
  - ".travis.yml"
92
93
  - Gemfile
93
94
  - LICENSE.txt
@@ -119,11 +120,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
120
  version: '0'
120
121
  requirements: []
121
122
  rubyforge_project:
122
- rubygems_version: 2.2.2
123
+ rubygems_version: 2.5.1
123
124
  signing_key:
124
125
  specification_version: 4
125
126
  summary: Validates the email format with the email_regex gem.
126
127
  test_files:
127
128
  - spec/email_format_validator_spec.rb
128
129
  - spec/spec_helper.rb
129
- has_rdoc: