has_email_authentication 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cfdfe7668bddb4d05f86c79270ccf8e4a018fa42
4
+ data.tar.gz: a9b0a059b801a3ef99e78fc005d2069041f474c6
5
+ SHA512:
6
+ metadata.gz: 8c559d07630a1e680a9fdaeec91a3761be7adc6bb7ef2e109a0ef15b56126be09031d42501f76bcf440d8899becc2cea76ba58a1b77da3c2138c18598047d17d
7
+ data.tar.gz: c650c67a21c94b9266ebd78fdffe01831406543c77d7c5266ae0ac7ee033928ac4b0614a9b6fd56243f174292038b3b36ca86f261452316887862941fec72efa
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+ gem "activerecord", "~> 4.0.0"
3
+ gemspec path: "../"
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+ gem "activerecord", "~> 4.1.0"
3
+ gemspec path: "../"
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+ gem "activerecord", "4.2.0.beta1"
3
+ gemspec path: "../"
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.0
5
+ - rbx-2.2
6
+ gemfile:
7
+ - .gemfiles/4.0.gemfile
8
+ - .gemfiles/4.1.gemfile
9
+ - .gemfiles/4.2.gemfile
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Michael van Rooijen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # Has Email Authentication
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/has_email_authentication.svg)](http://badge.fury.io/rb/has_email_authentication)
4
+ [![Code Climate](https://codeclimate.com/github/meskyanichi/has_email_authentication.png)](https://codeclimate.com/github/meskyanichi/has_email_authentication)
5
+ [![Build Status](https://travis-ci.org/meskyanichi/has_email_authentication.svg)](https://travis-ci.org/meskyanichi/has_email_authentication)
6
+
7
+ HasEmailAuthentication, for Rails/ActiveRecord 4.0.0+, is a micro library that compliments `has_secure_password` by providing `has_email_authentication`.
8
+
9
+ This library was developed for- and extracted from [HireFire].
10
+
11
+ The documentation can be found on [RubyDoc].
12
+
13
+
14
+ ### Compatibility
15
+
16
+ - Rails/ActiveRecord 4.0.0+
17
+ - Ruby (MRI) 2.0+
18
+ - Ruby (RBX) 2.2+
19
+
20
+
21
+ ### Installation
22
+
23
+ Add the gem to your Gemfile and run `bundle`.
24
+
25
+ ```rb
26
+ gem "has_email_authentication"
27
+ ```
28
+
29
+
30
+ ### Example
31
+
32
+ This library requires you to have an `email` column in the table associated
33
+ with the model you're using.
34
+
35
+ ```rb
36
+ class User < ActiveRecord::Base
37
+ has_email_authentication
38
+ end
39
+ ```
40
+
41
+ This does a few things:
42
+
43
+ - Adds presence, format and uniqueness validations on `email`
44
+ - Downcases `email` before saving the record
45
+ - Provides a `User.find_by_email(params[:email])`
46
+ convenience method which downcases the provided email
47
+
48
+
49
+ ### Contributing
50
+
51
+ Contributions are welcome, but please conform to these requirements:
52
+
53
+ - Ruby (MRI) 2.0+
54
+ - Ruby (RBX) 2.2+
55
+ - ActiveRecord 4.0.0+
56
+ - 100% Spec Coverage
57
+ - Generated by when running the test suite
58
+ - 100% [Passing Specs]
59
+ - Run test suite with `$ rspec spec`
60
+ - 4.0 [Code Climate Score]
61
+ - Run `$ rubycritic lib` to generate the score locally and receive tips
62
+ - No code smells
63
+ - No duplication
64
+
65
+ To start contributing, fork the project, clone it, and install the development dependencies:
66
+
67
+ ```
68
+ git clone git@github.com:USERNAME/has_email_authentication.git
69
+ cd has_email_authentication
70
+ bundle
71
+ ```
72
+
73
+ Ensure that everything works:
74
+
75
+ ```
76
+ rspec spec
77
+ rubycritic lib
78
+ ```
79
+
80
+ To run the local documentation server:
81
+
82
+ ```
83
+ yard server --reload
84
+ ```
85
+
86
+ Create a new branch and start hacking:
87
+
88
+ ```
89
+ git checkout -b my-contributions
90
+ ```
91
+
92
+ Submit a pull request.
93
+
94
+
95
+ ### Author / License
96
+
97
+ Copyright (c) 2014 Michael van Rooijen ( [@meskyanichi] )<br />
98
+ Released under the MIT [License].
99
+
100
+ [@meskyanichi]: https://twitter.com/meskyanichi
101
+ [HireFire]: http://hirefire.io
102
+ [Passing Specs]: https://travis-ci.org/meskyanichi/has_email_authentication
103
+ [Code Climate Score]: https://codeclimate.com/github/meskyanichi/has_email_authentication
104
+ [RubyDoc]: http://rubydoc.info/github/meskyanichi/has_email_authentication/master/frames
105
+ [License]: https://github.com/meskyanichi/has_email_authentication/blob/master/LICENSE
106
+ [RubyGems.org]: https://rubygems.org/gems/has_email_authentication
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ RSpec::Core::RakeTask.new(:spec)
4
+ task default: :spec
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "has_email_authentication/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "has_email_authentication"
7
+ spec.version = HasEmailAuthentication::VERSION
8
+ spec.authors = ["Michael van Rooijen"]
9
+ spec.email = ["michael@vanrooijen.io"]
10
+ spec.summary = %q{A micro library that compliments has_secure_password by providing has_email_authentication.}
11
+ spec.homepage = "http://meskyanichi.github.io/has_email_authentication/"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency "activerecord", ">= 4.0.0"
20
+ spec.add_development_dependency "bundler"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rspec"
23
+ spec.add_development_dependency "sqlite3"
24
+ spec.add_development_dependency "database_cleaner"
25
+ spec.add_development_dependency "pry"
26
+ spec.add_development_dependency "simplecov"
27
+ spec.add_development_dependency "yard"
28
+ end
@@ -0,0 +1,48 @@
1
+ module HasEmailAuthentication::Module
2
+
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ end
6
+
7
+ module ClassMethods
8
+
9
+ # Generates the +find_by_email+ class method. Downcases the +:email+
10
+ # attribute before saving. Validates the presence, format and uniqueness
11
+ # of the +:email+ attribute.
12
+ #
13
+ # @example
14
+ #
15
+ # class User < ActiveRecord::Base
16
+ # has_email_authentication
17
+ # end
18
+ #
19
+ # User.create(email: "MICHAEL@example.com")
20
+ # User.find_by_email("michael@EXAMPLE.com)
21
+ #
22
+ def has_email_authentication
23
+ validates :email,
24
+ presence: true,
25
+ format: { with: /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i },
26
+ uniqueness: { case_sensitive: false }
27
+
28
+ before_save do
29
+ self.email = email.try(:downcase)
30
+ end
31
+
32
+ extend(FindByEmail)
33
+ end
34
+ end
35
+
36
+ module FindByEmail
37
+
38
+ # Convenience method for finding a record by email. Attempts
39
+ # to downcase the provided +email+ prior to searching the database for it.
40
+ #
41
+ # @param email [String] the email to find the record by.
42
+ # @return [Object, nil]
43
+ #
44
+ def find_by_email(email)
45
+ find_by(email: email.try(:downcase))
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,3 @@
1
+ module HasEmailAuthentication
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,8 @@
1
+ module HasEmailAuthentication
2
+ require "has_email_authentication/module"
3
+ require "has_email_authentication/version"
4
+ end
5
+
6
+ if defined?(ActiveRecord::Base)
7
+ ActiveRecord::Base.send(:include, HasEmailAuthentication::Module)
8
+ end
@@ -0,0 +1,34 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe HasEmailAuthentication do
4
+
5
+ let(:user) { User.new }
6
+
7
+ it "validates the presence of the email" do
8
+ expect(User.create.errors[:email]).to include("can't be blank")
9
+ end
10
+
11
+ it "validates the format of the email" do
12
+ ["mike", "mike@", "mike@example", "mike@example."].each do |value|
13
+ expect(User.create(email: value).errors[:email])
14
+ .to include("is invalid")
15
+ end
16
+ end
17
+
18
+ it "validates the uniqueness of the email" do
19
+ email = "michael@example.com"
20
+ User.create!(email: email)
21
+ expect(User.create(email: email).errors[:email])
22
+ .to include("has already been taken")
23
+ end
24
+
25
+ it "should downcase the email" do
26
+ user = User.create(email: "MICHAEL@example.com")
27
+ expect(user.reload.email).to eq("michael@example.com")
28
+ end
29
+
30
+ it "should provide a method to find by downcased email" do
31
+ user = User.create(email: "michael@example.com")
32
+ expect(User.find_by_email("MICHAEL@EXAMPLE.COM").id).to eq(user.id)
33
+ end
34
+ end
@@ -0,0 +1,19 @@
1
+ $LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
2
+ require File.expand_path("../support/env", __FILE__)
3
+
4
+ require "database_cleaner"
5
+ require "simplecov"
6
+ SimpleCov.start
7
+
8
+ require "has_email_authentication"
9
+ require File.expand_path("../support/models", __FILE__)
10
+
11
+ RSpec.configure do |config|
12
+ config.before do
13
+ DatabaseCleaner.start
14
+ end
15
+
16
+ config.after do
17
+ DatabaseCleaner.clean
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ ActiveRecord::Base.establish_connection(
2
+ adapter: "sqlite3", database: ":memory:"
3
+ )
4
+
5
+ class Schema < ActiveRecord::Migration
6
+
7
+ def change
8
+ create_table :users do |t|
9
+ t.string :email
10
+ end
11
+ end
12
+ end
13
+
14
+ silence_stream(STDOUT) do
15
+ Schema.new.change
16
+ end
@@ -0,0 +1,10 @@
1
+ require "pry"
2
+ require "sqlite3"
3
+ require "active_record"
4
+
5
+ ROOT_PATH = File.expand_path("../../..", __FILE__)
6
+ SPEC_PATH = File.join(ROOT_PATH, "spec")
7
+
8
+ I18n.enforce_available_locales = true
9
+
10
+ require "#{SPEC_PATH}/support/db"
@@ -0,0 +1,3 @@
1
+ class User < ActiveRecord::Base
2
+ has_email_authentication
3
+ end
metadata ADDED
@@ -0,0 +1,195 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: has_email_authentication
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michael van Rooijen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: database_cleaner
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: yard
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description:
140
+ email:
141
+ - michael@vanrooijen.io
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gemfiles/4.0.gemfile"
147
+ - ".gemfiles/4.1.gemfile"
148
+ - ".gemfiles/4.2.gemfile"
149
+ - ".gitignore"
150
+ - ".rspec"
151
+ - ".travis.yml"
152
+ - Gemfile
153
+ - LICENSE
154
+ - README.md
155
+ - Rakefile
156
+ - has_email_authentication.gemspec
157
+ - lib/has_email_authentication.rb
158
+ - lib/has_email_authentication/module.rb
159
+ - lib/has_email_authentication/version.rb
160
+ - spec/lib/has_email_authentication_spec.rb
161
+ - spec/spec_helper.rb
162
+ - spec/support/db.rb
163
+ - spec/support/env.rb
164
+ - spec/support/models.rb
165
+ homepage: http://meskyanichi.github.io/has_email_authentication/
166
+ licenses:
167
+ - MIT
168
+ metadata: {}
169
+ post_install_message:
170
+ rdoc_options: []
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ requirements: []
184
+ rubyforge_project:
185
+ rubygems_version: 2.2.2
186
+ signing_key:
187
+ specification_version: 4
188
+ summary: A micro library that compliments has_secure_password by providing has_email_authentication.
189
+ test_files:
190
+ - spec/lib/has_email_authentication_spec.rb
191
+ - spec/spec_helper.rb
192
+ - spec/support/db.rb
193
+ - spec/support/env.rb
194
+ - spec/support/models.rb
195
+ has_rdoc: